Script debugging
All  1  2-6

Previous
Next
 From:  dan (DANLANIGAN)
8264.2 In reply to 8264.1 
Just found a thread on DisableFileCaching setting in moi.ini. This should fix the restarting headache. Any other tips? Thanks
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
8264.3 In reply to 8264.2 
Hi dan,
Here are some of my amateur "techniques" :-) on Windows 7, and amateur opinions, for everyone's amusement:-)
I have a subdirectory call SCRIPTS, which contain a subdirectory for each project.
My version control is poor.
I use Notepad++ for editing. Hardcopy printouts are shadowy :-(
In Notepad++, there are two windows, left and right, each of which can hold many files. Cut and paste can be done between windows.
Files can be easily swapped between the windows. File save and undo are easy.
Do not use the .html extension. .html does not work. To save as .htm with the .html save offering, add .htm extension to the end of the file name.
Once started with .htm or saved as .htm, just hit the save floppy icon. There is no reversion to .html.
I usually select an existing script which functions well and has compatible code to the new project, copy it to the project directory, and rename it to the
new project name.
There are several "styles" of programming, Michaels excellent styles, and Max's excellent and tough for me to understand code.
Script in the .htm file lacks "debug" help, and may not work for "peculiar reasons", so it is better to script in the .js file, and later move it to .htm script
section for speed, if needed. There are multiple ways to work with Factories and the Geometry Database.

For the directory library, I created a link to MoICommands subdirectory, to assist copying .js and .htm files from the SCRIPTS sub sub directory to the MoI
program commands directory.

It is very important for me to always work with a functioning program, and make small changes, and tweak them until they function properly, or UNDO them.
Making massive changes which do not work makes it difficult to "debug."
Also, set up a "WorkingSoSo" file and save versions which actually partially function, such as draw some rudimentary curve on the screen.
Then, after making a bunch of changes which do not function, the SoSo version can be reverted to.
Temporary Alerts can be inserted to glean what the new program is doing.
It is important to avoid spelling differences, such as capitalized vs uncapitalized variables, so be consistent with names, and use descriptive names, not single character names. I study Michaels scripts intensively, and try to mimic them, and their "styles." They can be "complex..."
Asking Michael for help is another good method, as he is superb and knowledgeable. I try not to ask for help, until exhausting "permutations."

Another method is to use Visual Studio 2015 community edition, free, which can have a project directory and solution (file?).
Hardcopy printouts are nice. As a new user, VS2015 community edition seems to be particularly difficult to figure out.
.js and .html should not be directly loaded, but should be in the project and/or solution files/directories/?, loaded in some unknown and inscrutable fashion.
(I'll have to read the directions sometime:-)

Link can be made to your own github account. See YouTube articles by Donnie Santos https://www.youtube.com/watch?v=8lk6BSsX2g4
and https://www.youtube.com/watch?v=zNANRs0nZfU I have not quite actually done this yet :-(

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
8264.4 In reply to 8264.1 
Some excellent tips from Brian above, thanks Brian!

For getting information about what's going on you put in moi.ui.alert( 'text' ); to pop up an alert dialog. If you need to spew out a bunch more information you can instead use moi.log( 'text' ); which will put the text into MoI's text log instead of popping up a dialog, then the whole log can be shown with a shortcut key with script:moi.ui.createDialog( 'ShowLog.htm' );

And that's about it currently... Definitely doing things in an incremental way like Brian describes helps a lot. In the future I would like to work on making it easier to do this with some kind of integrated script debugger where you could set breakpoints and view variable values and things like that, but I won't know how much work is involved until I dig into it some.

@Brian, re:
> Script in the .htm file lacks "debug" help, and may not work for "peculiar reasons", so it
> is better to script in the .js file, and later move it to .htm script section for speed, if needed.

One of the things that I've changed with v4 is that the script from the .js file will now be run directly in the main thread instead of in a separate moi_commandprocessor.exe process, so there won't be any speed penalty for the .js code anymore. The down side of this though is that it will be easier to lock up MoI if the script goes into an infinite loop or something but that will already happen anyway with code run on the .htm side of things.

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  bemfarmer
8264.5 In reply to 8264.4 
Thank you Michael for the information.

I've added a new shortcut key inside MoI, Options, Shortcut keys, with your shortcut key script for ShowLog.

Good news on the .js "speedup".

When I write bad code which causes a lockup when testing a new script in MoI, I press CtrlAltDelete, hit "Start Task Manager,"
to bring up Windows 7 Task Manager, and under Applications, highlight MoI, and hit End Task. This closes MoI, ending the lockup.
(I don't think good code causes such lockups...AFAIK)

- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  dan (DANLANIGAN)
8264.6 
Brian,

Thanks for your many tips, some I was aware of but others not. I'll see how much of this I can incorporate into my own workflows.

Michael,

I was aware of the ui.alert method but not the log, I'll see how I can use this to my advantage going forward, thanks.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1  2-6