Asked — Edited

Converting EZ Script To Javascript That Jumps Around With Goto Commands &Amp; Labels

EDIT: I screwed up and inserted the wrong script but have now replaced it with the proper one. This one does repeat 3 times. I'll do a septate post with the script that only runs once. Sorry for any confusion.

Hi, as requested in another thread I'm posting the following script and asking @Athena to help convert it to Javascript. It's very long at over 1400 lines. I'm posting the entire script because as it's executed it jumps around a lot from top to middle, then back towards the top then to the end.

*This EZ Script lets my B9 robot from the TV show Lost In Space do impersonations (or impressions) of all the characters of that show (sound clips stored in various ARC Soundboards) including Dr Smith, Will Robinson and his family. It will also do impressions of other famous robots like Hal, Robby the Robot, Bender, R2D2 and other film and TV robots along with a few special effect sounds. Each character has many different sound clips (from 4 to as many as 30 or more) that can be spoken. *Each sound clip is assigned it's own number and they are selected using the random number generation command in ARC. This gives statements, answers and the impersonations process a truly random feel.  *Each time the script runs it will have the robot say three different random characters impersonations. Each character's impersonations is said only once (using sound clips stored in various ARC Soundboards) and each of the clips will be selected randomly.

I've written this EZ Script using GoTo commands, Labels, Return, Repeat, If Statements and a lot of random generation of numbers to choose sound files that make the robot respond differently each time and his impersonations random. I also use Controlcomand() to start up other scripts and AutoPosition controls that run anamations, servos and DC motors. In addition it relies heavily on Global Variables. Kind of like this:

"Robot, Do an impersonation of Dr Smith".

*The EZ Script pauses the Speech Recognition and Personality Generator then a GoTo command will send it to the section where the robot says a random acknowledgment that he heard you then it will return to where is came from.  *Then it will be sent to the random character section (Each character has his own section). *This will repeat three times with the robot making a statment between each impression. This is done using the GoTo command. *Once the impersonation process has repeated three times the Goto command will send the script to the end of the script for the robot to do a closing routine and return all motors and functions to a rest or starting position.  *Finally all Variables will be reset.

The following is the EZ Script I need to convert to JavaScript. @Athena , can you help me convert it? The script includes Goto statements, Labels, Return, Repeat, If Statements and a lot of random generation of numbers for subroutines and random selection of states. I would appreciate your guidance on how to translate this functionality into JavaScript:

I welcome any advice from anyone else. Thanks!

File: original ezscript.txt


ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

#9  

Quote:

Argh, i started to edit your original script but noticed you changed it. So i just did a bunch of work for nothing. But anyway. I was able to use search and replace to change most of it. The only thing left is to change the goto's to functions. And then add more opening braces { on the end of the IF conditions. I even fixed the broken ELSE conditions.
Oh man! I'm sorry DJ! I had no idea you were doing this.

I can't wrap my head around how fast you were able to convert and fix this to this level. You must have super powers.

I'll study what you sent in that link and try to learn so I can finish it up.

Thanks again my friend. You're the best.

#11  

Hey @DJ, if you're still there, I noticed in your changes that you also removed the Endif commands after my IF, ElseIf statements. After looking around tutorials on the internet I don't see any mention of having to use Endif with JS. Was this just an EZ Script thing?

#12  
Okay so this is almost perfect. I haven't tested any logic but most of the code has been converted

Wow, nice. I'm flabbergasted that you did this for me. Using this I think I can learn much easier how to proceed with converting my other scripts. They are a lot less complex. Thanks for all your work. I wish I could buy you a beer or something to show my gratitude.

PRO
Synthiam
#13  

Okay i think this is everything. Take a quick look and see if there's something i missed or any errors. I can't run it becuase i don't have the main project but it looks fine: revised script 2.js

#15  

Again, I can't say how much I appreacheate your work on this.

I did notice there were a few GoTo's in your first revision but they are gone now. Looking over this quickly it looks good as far as I know. Your work has helped me see how everything needs to be. I still need to do more studying to really grasp it though.

I'll have to wait till tomorrow and run this new script on the robot to see if it flows.

I'll let you know how it goes.

PRO
Synthiam
#16  

Just remember the only difference is how if conditions and loops use curly braces.

@athena give Dave examples of how curly braces are used in JavaScript with arc