Migrating from EZ-Script to JavaScript

Variables

The first thing to cover are how variables differ. A variable in EZ-Script starts with a $ (dollar sign). A variable in JavaScript does not start with anything and can be named however you wish, as long as the first character is not a number.

Assign Variable Example

EZ-Script Example Here is an example of a variable being created in EZ-Script

$MyVariable = "Some text"

print($MyVariable)

JavaScript Equivalent This is the equivalent of assigning a value to a JavaScript variable

var MyVariable = "Some text";

print(MyVariable);

*Note: Remember that variables are case-sensitive. This is covered in an previous step of this tutorial.

JavaScript Variables Are Not Global Across ARC

This is one difference that you must be aware of. When creating a variable in EZ-Script, the variable is accessible across all robot skills in ARC. However, when creating a variable in JavaScript, it is only accessible by that isolated script. To share variables across other robot skills, you will use the getVar() and setVar() commands. That will set a global variable with a value so other robot skills can see it.

In fact, setting and getting variables from the Global Variable storage will also work across EZ-Script variables. EZ-Script sets variables as global by default. So, if you assign a variable in EZ-Script, you can retrieve it in another robot skill using JavaScript with the getVar() command.

Example of Using Global Variables If you have a variable that you would like to share with other robot skills, use the setVar() function. This will push the variable's current value into the global stack so it is available by other robot skills.

var myVariable = "This is some text";

setVar("$myVariable", myVariable);

In that example, the global $myVariable will be assigned the value of JavaScript value of myVariable. This means that in another robot skill, you can retrieve that value.

var myVariable = getVar("$myVariable");

print(myVariable);

[head2]Global Variable Viewer[/head] The global variable viewer will display all variables in ARC. By clicking on a variable, it will insert the setVar() command where the cursor is.


ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

#1  

Wow that is totally great info to know, thanks!

#2  

Thanks for this Tutorial @DJ. It will be invaluable as I change over my many scripts from EZ Script to JavaScript! I'm excited to see how my robot's arm servo react to the new faster language. I have some pretty complex scripts (for me anyway. LOL).

PRO
Synthiam
#3  

I think you'll find that the new scripts you write will be even smaller and faster. Probably easier to read as well. I can always help you change some over if you post one. That'll give you examples of how the difference would be.

#4   — Edited

But just to be clear, the EZ scripts should still mostly work in Arc? I tried 2 that still worked no conversion. Just slower most likely.

PRO
Synthiam
#5  

Yeah, EZ-Script works in ARC. This is a tutorial to help people migrate to a faster and more feature-rich language.

#6  

Wow @DJ. That's an amazing offer. Thanks! I'll post one soon. I think I have covid now and need to get past that first. Can't quite thing straight right now. LOL.

PRO
Synthiam
#7  

Oh boy, it seems everyone is getting covid these days. I'm feeling left out. I hope you're doing well and binge-watching a lot of tv! Drink soup and dream about robots.

#8  

Thanks DJ. I'm coming to the end of it I hope. Feeling better. Don't feel left out. Only good thing about this is now I have some antibodies for a while. LOL. Stay healthy!