Migrating from EZ-Script to JavaScript

IF ELSE ELSEIF

JavaScript = uses ==

That's right, when comparing two values in JavaScript IF condition, use == instead of a single =. This is because a single = is reserved for assigning values. The double == is reserved for comparing values.

var myVariable = 5;

if (myVariable == 5) {

  print("You got it");
}

That's the only difference for comparisons. Using > greater than, < less than, >= greater than equal to, <= less than equal to, etc.. are all the same.

[head2]Not Equals[/head] Not equals puts an ! exclamation mark in front of the = equal sign in the comparison.  This means that the value is not equal to another value.

var myVariable = 5;

if (myVariable != 10) {

  print("The value does not equal 10");
}

JavaScript Uses Brackets

In EZ-Script, an IF condition ends with an ENDIF. JavaScript operates the same way but uses { brackets } instead. This is called the scope, when code is between the brackets. In EZ-Script, the scope is between the IF and ENDIF statements. In JavaScript, the scope is between the { opening bracket and } closing bracket.

EZ-Script

$myVariable = 5

if ($myVariable == 5)
  print("You got it")
endif

JavaScript

var myVariable = 5;

if (myVariable == 5) {

  print("You got it");
}

IF ELSEIF ELSE

This is pretty much the same as EZ-Script, by having ELSE IF and ELSE commands.


var myVariable = 5;

if (myVariable == 5) {

  print("You got it");

} else {

  print("Nope, missed");

}

or similar example using ELSE IF


var myVariable = 5;

if (myVariable == 5) {

  print("You got it");

} else if (myVariable = 6) {

  print("So close");

} else {

  print("Nope, missed");

}

Single Command Doesn't Require Brackets

Occasionally you may see an IF condition with no brackets. That is because you may only have one command after the IF, therefore you do not require brackets. This is similar to the basic programming language, where a single IF that doesn't have ENDIF means only use the next command.

EZ-Script

$myVariable = 5

if ($myVariable = 5)
  print("You got it")
endif

JavaScript

var myVariable = 5;

if (myVariable == 5)
  print("You got it");

ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

#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!