[dev mode]Monitoring of script variables

Request a new command, feature, or improvement

Moderator: MSandro

Post Reply
SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

[dev mode]Monitoring of script variables

Post by SimpleSi » Oct 21st, '17, 12:04

Its much better/easier to use script variables than shared or instance variables as they can be created "on the fly"

However, monitoring their values requires work (print to console - use say block, use own created shared dictionary, insert halts and step thru etc etc)

I think we could do with something easier - not sure what

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: [dev mode]Monitoring of script variables

Post by JohnM » Oct 23rd, '17, 22:49

You're right that you can't make a monitor on a script variable. That's because the variable only exists momentarily, while the script is running.

However, "say" or "print to console" do work -- they capture the value of the script variable at the moment they are executed.

And you're also right the script variables are convenient and useful. I use them often to store the restore of some computation. It not only makes my code shorter, it also make it easier to read because a good variable name tells the reader what that variable is or what it's purpose is. But the fact that they are transient and that you can't create a monitor on them make them a more advanced concept, so they are only available in developer mode.

One other place you can see tha value of script variables is in the debugger. You can add a "halt" block to a script to make the debugger appear, then use the "step" button to go through the code one command at a time. The script variable names are shown in the bottom left pane. Selecting one shows it value.

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: [dev mode]Monitoring of script variables

Post by SimpleSi » Oct 24th, '17, 06:01

One other place you can see tha value of script variables is in the debugger. You can add a "halt" block to a script to make the debugger appear, then use the "step" button to go through the code one command at a time. The script variable names are shown in the bottom left pane. Selecting one shows it value.
Unfortunately, that's not practical if the script is longer than a screen's worth as debugger goes back to the top of the script everytime we press Step and you spend all your time scrolling up and down and re-selecting any variable you want to monitor

If the debugger didn't move back to the top each time then it could be a workable method

SimpleSi
Posts: 330
Joined: Jul 2nd, '17, 13:47

Re: [dev mode]Monitoring of script variables

Post by SimpleSi » Oct 28th, '17, 21:30

EUREKA MOMENT

Make a shared var called varMonitor and stick a monitor of it up next to class name

then to monitor a local var (e.g i)

add

set shared varMonitor to i

at appropriate place in the script

:-)

And or course it can all be done while the program is looping away

JohnM
Posts: 379
Joined: Sep 11th, '15, 14:42

Re: [dev mode]Monitoring of script variables

Post by JohnM » Oct 28th, '17, 21:55

Yep!

In GP, monitors can be put anywhere, not just on the stage. That's useful because often the stage is shrunk down so monitors are not readable. By putting the monitors elsewhere (e.g. along the top bar) you can see what's going on with your variables even when the stage is tiny.

Post Reply