Thank you Craig, that was a good point, and summed up a lot better than I did.
teriibi wrote: ↑Mon Feb 19, 2018 10:03 pm
tks bogs, I tested both script but couldnt nothe a behavior diference. ..guess I need more coffee
No problems, the example was pretty poorly constructed, but I'll show you the difference between the two. First, an explanation of why I set it up with two handlers.
If you had all the statements in a single handler, a variable created on the fly would work, because the variable is within the handler. In the first example of code, the variable tmpUndeclaredVar is actually 2 separate variables, despite being named the same. Now for what you (should) have seen -
No local variable (above the script) - on the mouse entering the button, you should see nothing more than an answer dialog with 'tmpUndeclaredVar' , the name of the variable created on the fly. The reason you see that is because we didn't put anything into 'tmpUndeclaredVar' in that handler, and because it is in that handler, nothing out side of that handler is ever going to put anything into it.

- Mouse entering the button...
The second handler, mouseUp, *does* put something into the 'tmpUndeclaredVar' within this handler, in this case when you click on the card, it puts the short name of the stack into 'tmpUndeclaredVar', and then pops up the answer dialog with that shown.

- Mouse click on the card...
- Selection_005.png (18.79 KiB) Viewed 8031 times
To prove to yourself that both of these variables are completely separate, regardless of the name being the same, you can now have the mouse enter the button again, and you will see the first picture with the answer being 'tmpUndeclaredVar'. We know that the tmpUndeclaredVar in the mouseUp handler has a value, but the mouseEnter handler will never see this.
As a result, if you were expecting such a variable to have a certain value, your program will not be able to put it into effect if called from a separate handler.
Local variable (above the script) - Now you'll see if you click on the card after declaring "local tmpDeclaredVar" (and changing the names in the mouseEnter / mouseUp handlers) that the variable really is available over all the handlers that follow it, as Craig pointed out.

- Click on card fills the variable...
- Selection_006.png (11.02 KiB) Viewed 8031 times
If you mouseEnter the button now, you will see the same answer, the short name of the stack.
As Craig also pointed out, you can change the behavior quite a bit of a 'local variable', depending on where you put it. My tendency when programming is to declare all variables right at the top, and I keep a running list of those in a text program since it usually only requires a few lines.
For most things, you are not going to require massive amounts of variables, so using unique ones isn't a vast strain.