Re: keeping score
Posted: Thu Feb 25, 2016 3:00 pm
Ethan,
As you would expect, scope in LC is always confined to the lowest level, i.e. a handler (on mouseUp, on openCard, etc.), unless you specifically override it using either the local or global keywords. local variables can, at most, have scope within a script (remember, a script is represented by a tab in the Script Editor (a button, field, card, etc.)). global variables can have scope anywhere, but they have to be declared in each script or in each handler or they will not be known to that script or handler.
In any script, there are two ways to declare scope:
a) For the entire script: In the example below, the score variable has scope in the entire script, because it is declared outside of any handler.
b) For a particular handler in a script. In the example below, the score variable only has scope in the mouseUp handler, but not in the mouseDown handler.
local is not appropriate in your case, because local variables can only have scope within handlers in a script. In your case, if you want to have score be initialized in the openCard handler for the card, and then modified in the on mouseUp handler of a button, then declare it as global in both places.
Remember, scope is local to a handler by default. No matter what you do, the only way to access globals in a script is to declare them. A script is a tab in the Script Editor.
As you would expect, scope in LC is always confined to the lowest level, i.e. a handler (on mouseUp, on openCard, etc.), unless you specifically override it using either the local or global keywords. local variables can, at most, have scope within a script (remember, a script is represented by a tab in the Script Editor (a button, field, card, etc.)). global variables can have scope anywhere, but they have to be declared in each script or in each handler or they will not be known to that script or handler.
In any script, there are two ways to declare scope:
a) For the entire script: In the example below, the score variable has scope in the entire script, because it is declared outside of any handler.
Code: Select all
global score #putting it outside of a handler gives it scope in the entire script
on mouseup
...
end mouseUp
on mouseDown
...
end mouseDown
Code: Select all
on mouseup
global score #putting it in the mouseUp handler means it only has scope in the mouseUp handler
...
end mouseUp
on mouseDown
...
end mouseDown
Remember, scope is local to a handler by default. No matter what you do, the only way to access globals in a script is to declare them. A script is a tab in the Script Editor.