Hello community
Small technical question about SD8:
SD8 allows you to see in real time the values of the variables in the small dedicated window. But this window never mentions the value of the variables when the program goes through the handlers. Is this a parameter to change to be able to do this?
Thank you for your attention
Jérôme
WIth Script Debugger you can see the values of properties, globals and declared local variables. If you want to see the value of a local variable in a handler declare using a line like this inside the handler:
local handler1Name, handler2Name
You can use this syntax in handlers to see the value in the dedicated window on a break point
--= varName
Note: The variable must already be assigned at this point:
on myHanler(a)
--= a
set b to a + 1
--= b
set c to b + 2
--= c
end myHanler
Sorry, I’m not sure I understand the answers. Here is a screenshot. I have the value “valeur_01” in my window but I can’t see the value “valeur_02” or “valeur_03”.
These are the ones I would like to know when I run the entire program :
You can see those values when you step through the handler, but once your code leaves the handler, its local variables essentially cease to exist, so they have no value. if you want them to persist, declare them as globals at the top of the script.
The ScriptDebugger Help documents describe this pretty well.
But try stepping through this script
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
set valeur_01 to 3
my MyHandler(valeur_01)
my MyHandler01(valeur_01)
on MyHandler(a)
set valeur_02 to a + 1
set valeur_03 to valeur_02 + 2
end MyHandler
on MyHandler01(a)
local a, valeur_02, valeur_03
set valeur_02 to a + 1
set valeur_03 to valeur_02 + 2
return valeur_03
end MyHandler01
You’ll notice that as you step through the first handler you don’t see the local variables.
But when you step through the second handler you do see them because they have been declared in that handler. (But, as Shane pointed out, you can’t see them outside the handler or after the script runs)
(Also, there’s an AppleScript thing were variables in the top level of the script (the explicit run handler) act like globals and you can see their values and they do perist.
Wow, Dirk, that’s pretty cool! It’s not documented and may just be a bug/feature, but it definitely works.
I thought AppleScript ignored everything after the – at the start of a line, but it’s actually doing something, which puts the variable in a weird state. It’s still local, but it’s not declared, and it doesn’t act like a declared local (as you point out if you use the --= before it has a value it won’t work.
Where did you learn about this?
We recommend using the local
statement to declare local variables. When Script Debugger sees a local
statement, it will track the variable from that point onward and automatically update the variable’s value as it changes while a handler executes.
The —=
comment is a Script Debugger specific thing which echos the value of the named variable at that point in the script. It does not add the variable to the list of declared variables that are automatically tracked.
The —=
comment is mentioned in the Script Debugger help. This dates back a the time when Script Debugger’s parsers wen’t as good as they are now and would sometimes miss instances where a local variable was updated. This can still happen when variable values are updated through a reference, but it’s rare.
I’ll add that being explicit about the scope of your variables has the benefit of working around some of the special cases in AppleScript. For instance, variables created within on run
and on open
handlers are, by default, global in scope while variable created within named handlers are, by default, local in scope. By being explicit using a local
or global
statement you make your scope intention clear.
Interesting discussion! Thanks a lot.
That answers well.
Thanks Dirk, Ed, Shane.
3 tips that answer my question!
and thanks alldritt for the explanations