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.
That's what super heros are made of!
Actually i was adding some script codes for my Init servos start up and other start up functions, then realized I used EZ script instead of Javascript. Since Javascript is way faster ,what is the easy way to convert the EZ script over to Javascript? right now it just wants to delete the whole EZ script when I move into Javascript window. Like if I copy and paste it in, will it convert? I guess I can just start over line by Line with the cheat helper Edit.... I think I had a similar question last week about using my old EZ scripts and did you point out some tutorial Link? I seem to have forgot where.
*Note: I moved your question to the appropriate thread because it was asked on a feature request for Blockly copy and paste
The windows Copy and Paste command will copy the text. There is no way to "convert code" when pasting. It will merely paste what is copied. Once you paste the EZ-Script into the JavaScript window, you can edit the code to make it JavaScript syntax.
Ahh yes That was what I was looking for thanks again, sorry for asking twice,LOL!
How to include a javascript library ?
There used to be an option for that. Hmmm. I can't seem to find it now. I'll have to take a better look as I don't see it in the documentation on the support section.
....just stumbled onto this...thank you so much.
OK, I'm having trouble wrapping my mind around converting my EZ Script to JavaScript. I do think I understand some of the basics ways to write in JS like loops, classes and variables. However I I have a very complicated but working EZ script I wrote a few years ago I'm trying to convert to JS but I don't understand some of the proper ways to write commands.
Here are a couple of the commands I'm having trouble understanding. I'll show the EZ Script command that works and try to show the way I think the JS command will work. If some one can guide me to the correct syntax I would be grateful:
In this first example I am sending a command through EZB 2, Uart 2 to a Kangaroo Motor controller. The Roo's command is inside the " ". It states which channel on the Roo to start the move on, the position to move to and at what speed. The next command in the line, 0x0d, is the ASCII value for the Return Key on a keyboard. The Roo needs this to accept the command:
Below is what I think the JS Syntax should be??? Notice the 0x0d ASCII value and the uart port and EZB index numbers. Do I need those quote marks? How close am I in being correct?
Now, My next big problem. How to split and GetCharAt with JS. When the I request a position and the Kangaroo motor controller returns this position to ARC through an EZB Uart, it comes back looking like this: Pxxx or pxxx. Their will be either a upper or lower case P followed by the position number (xxx). An upper case P means the motor is still moving and a lower case means it's stopped. I wrote an EZ script that puts this returned value into a variable, splits the P from the position number, tells me if the P is upper or lower case and what the position number is. The way I'm using this script is that I ignore the P and only need to position number. However I need to split the P from the returned value and ignore it or the script wont work:
Then I have the EZ Script decide if the motor has fully deployed the payload and it's safe to continue or it needs to go loop back and do everything over again until the payload in in position. It then sets a global variable which tells a different script that is waiting on this that i's safe to proceed. This EZ script loops until that safe position is reached (805) and sets that variable.
As you can see above this EZ Script is commanding two motors through one Kangaroo, I have no idea how to do the above with JS. I know I'll have to figure out a different way to do the looping as JS does not use GOTO and labels like this. If I could get some help with splitting returned characters and getting characters at a certain place this would be very helpful.
Here's the complete EZ Script for reference if it helps: Be kind. It's probably messy. LOL. Any ideas or advice are very welcomed that will improve it or help with conversion to JS. Thanks in advance!