Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
USA
Asked — Edited
Resolved Resolved by Dunning-Kruger!

Variables Not Global?

So, I thought I read somewhere in the forums that the variables that I create are all global. I wrote an "initialize" script that I run before any other script once I power up my EZB4. This script is for the purpose of declaring all of my variables, among other things.

I wrote another script that would not work. It contains variables that are declared in my "initialize" script which I run first. However after I declared the variables in the script which they are used in, then the script worked. Do I always have to declare variables in the script in which they are being used, or do I somehow need to specify that they are global variables so they can be used in other scripts?

If they have to be declared in the script in which they are being used, then how can I pass data from one script to another collected and stored in the form of variables?

Any guidance would be appreciated.

AI Support Bot
Related Content
Synthiam
#1  
Yes all variables ARE global... Just check and make sure you are not using any reserved ones like $day, $month etc....

Make sure you run the init script first before any other scripts.... Tip: You can use the variable watcher to help debug your scripts...
#2  
Echoing what Richard said. Definitely all global. When you run your Init script check the debug window (the little green window at the bottom) to make sure there was not an error. Such errors are easy to miss since they tend to quickly scroll off the window's viewing area. Any error encountered during the initialization process will stop the script from doing any more processing from that point on. Despite that, things will still appear in the window, causing the error to scroll off. So scroll back through it after running it.

Also, I don't know how many time I have looked at a variable that generated an error knowing full well that I initialized it. I looked at the initialization spelling and the spelling in the line that caused the error and just could not find any difference. Yet there was a difference. The quickest way to overcome that sort of thing is to copy the original and paste it over the one at the point of the error.
PRO
Synthiam
#3  
Add the variable watcher to see your variables. Also use the script flow control to see what your execution path looks like. Sounds that the execution path is not as expected. The script may not be declaring variables before they are being used / i.e. Time travels in only one direction.
#4  
Thanks Richard, I hadn't noticed the Variable Watcher before, that's a great help. As it turned out all but one variable were fine, of course that one was the wrench in my wheel.

Thanks everyone for quick replies. I'm off and running again!
PRO
Synthiam
#5  
When editing scripts, there is a variables tab to display all variables as well. That tab lets you click on a variable to add it to your code - so there can never be a spelling mistake. You will find more about it in the learn section tutorials for the ezscript editor. Here's a direct link: http://www.ez-robot.com/Tutorials/Lesson/23?courseId=6
#6  
Thanks, that's a great idea to avoid typo errors