Script variable not being reported correctly
Moderator: MSandro
Script variable not being reported correctly
I'm was expecting the say to produce 0 not 1
Re: Script variable not being reported correctly
You're right, this is a bug; your example should produce 0.
Did you happen to have a shared or instance variable with the same name as the local variable? It looks as though there is a cache that isn't getting cleared.
I couldn't reproduce this starting with a clean project, but I was able to create a similar problem by making a shared variable named 'var3' and then renaming the variable in the "let" block to 'var3'. Do you have a way to recreate the problem from an empty project?
In my case, switching to a different class and back seems to fix the problem (it clears the cache). Does that work for you?
Thanks for reporting this!
Did you happen to have a shared or instance variable with the same name as the local variable? It looks as though there is a cache that isn't getting cleared.
I couldn't reproduce this starting with a clean project, but I was able to create a similar problem by making a shared variable named 'var3' and then renaming the variable in the "let" block to 'var3'. Do you have a way to recreate the problem from an empty project?
In my case, switching to a different class and back seems to fix the problem (it clears the cache). Does that work for you?
Thanks for reporting this!
Re: Script variable not being reported correctly
I hadn't created any other variables - I was checking to see if Script Variables were just local to the script they were in or in scope across the whole instance
I see if I can re-create sequence
I see if I can re-create sequence
Re: Script variable not being reported correctly
This was my test script - running gave no says at all (so I assumed var and var2 were not in scope when I used say
So I then re-arranged to this (just to make sure the vars were actually being set) and just got the 0 reported as in orig bug report
So I then re-arranged to this (just to make sure the vars were actually being set) and just got the 0 reported as in orig bug report
Re: Script variable not being reported correctly
Got it! Following your sequence I was able to reproduce the problem and am on the track of a fix.
Glad you found this -- it's a very confusing bug.
Incidentally, you're correct that the variables were "out of scope" in your first test. The scope of a script variable is just the script in which it appears. Because of that, it's fine for multiple scripts to have script variables with the same name; they don't conflict with each other. In your first example, that's exactly what was happening: the two scripts with "say" blocks actually had their own, uninitialized script variables named 'var' and 'var2'. An uninitialized variable has the value 'nil' and "say nil" has the same behavior as "say nothing".
Script variables are extremely useful; I often use them to store intermediate results, with descriptive names to make the code easier to understand. However, the fact that their scope is limited to a single script, that they only exist when the script is running, and that in cases of multiple calls or recursion, every invocation of a script has its own copy of the script variables, makes script variables less easily "discoverable" than either shared or instance variables. That's why they are not available except in developer mode.
One way to understand script variables is to add a "halt" command to the script in which they appear. All the script variable names will appear in the bottom-left pane of the debugger that pops up. Selecting one of them will show it's value in the bottom-right pane.
Glad you found this -- it's a very confusing bug.
Incidentally, you're correct that the variables were "out of scope" in your first test. The scope of a script variable is just the script in which it appears. Because of that, it's fine for multiple scripts to have script variables with the same name; they don't conflict with each other. In your first example, that's exactly what was happening: the two scripts with "say" blocks actually had their own, uninitialized script variables named 'var' and 'var2'. An uninitialized variable has the value 'nil' and "say nil" has the same behavior as "say nothing".
Script variables are extremely useful; I often use them to store intermediate results, with descriptive names to make the code easier to understand. However, the fact that their scope is limited to a single script, that they only exist when the script is running, and that in cases of multiple calls or recursion, every invocation of a script has its own copy of the script variables, makes script variables less easily "discoverable" than either shared or instance variables. That's why they are not available except in developer mode.
One way to understand script variables is to add a "halt" command to the script in which they appear. All the script variable names will appear in the bottom-left pane of the debugger that pops up. Selecting one of them will show it's value in the bottom-right pane.
Re: Script variable not being reported correctly
That explains why I only noticed them today!That's why they are not available except in developer mode.
I've only been working in developer mode for a week and hadn't scrolled down that far in the variable category until today