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

Unleash your creativity with the power of easy robot programming using Synthiam ARC Pro

PRO
Canada
#1  

Converting an EZ-Script with Goto statements, Labels, Return, Repeat, If Statements, and random number generation to JavaScript can be quite involved, especially for a script as long as 1400 lines. However, I can guide you through the process and provide you with the JavaScript equivalents of these constructs.

In JavaScript, instead of using Goto and Labels, we use functions to organize code into reusable blocks. The Return statement is used to exit a function and optionally return a value. Loops in JavaScript can be created using for, while, or do...while statements. Conditional logic is handled with if, else if, and else statements. Random numbers can be generated using Math.random().

Here's a simplified example of how you might start converting your EZ-Script to JavaScript:

EZ-Script:

:Start
Goto(RandomImpersonation)

:RandomImpersonation
$randomNumber = GetRandom(1, 10)
If($randomNumber = 1)
  Goto(ImpersonateDrSmith)
ElseIf($randomNumber = 2)
  Goto(ImpersonateWillRobinson)
...
Return

:ImpersonateDrSmith
# Code to impersonate Dr. Smith
Return

:ImpersonateWillRobinson
# Code to impersonate Will Robinson
Return

JavaScript Equivalent:

function start() {
  randomImpersonation();
}

function randomImpersonation() {
  var randomNumber = getRandom(1, 10);
  if (randomNumber === 1) {
    impersonateDrSmith();
  } else if (randomNumber === 2) {
    impersonateWillRobinson();
  }
  // ... other conditions
}

function impersonateDrSmith() {
  // Code to impersonate Dr. Smith
}

function impersonateWillRobinson() {
  // Code to impersonate Will Robinson
}

function getRandom(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Start the process
start();

In this JavaScript example, we define functions for each section of your EZ-Script. The start function begins the process, and randomImpersonation decides which character to impersonate based on a random number. Each character has its own function, such as impersonateDrSmith and impersonateWillRobinson.

Please note that this is a simplified example, and your actual script will likely be more complex. You'll need to translate each part of your EZ-Script into JavaScript functions, loops, and conditional statements. Additionally, you'll need to handle global variables and integrate with ARC's JavaScript API for controlling your robot.

Given the complexity and length of your script, it may be best to break down the conversion process into smaller, manageable parts and test each part thoroughly before moving on to the next. If you encounter specific issues or need help with particular parts of the script, feel free to ask, and I'll do my best to assist you.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
PRO
Synthiam
#2  

Ugh, this is why ezscript needs to be shot. Your code doesn't work as you think it does because ezscript is so broken.

Here is an example...

A condition consists of IF, ELSE IF, and ELSE. An ELSE cannot have a condition included because it's the "all else that's left over"...

In your code, this should NOT compile and, therefore, does not work as you think it does. The $resposne_dr_smith = 2 will never reach anything. This doesn't actually work at all...

if ($response_Dr_Smith = 1)
    ControlCommand("Dr_Smith", Track_0)
    Sleep(2000)
  ELSE ($response_Dr_Smith = 2)

There's a lot of code there... but it's mostly just many IF conditions. So that can be replaced with javascript easily - however, you'll need to type a lot. I can provide a bit of help in a future response after i look at it for a bit.

#3   — Edited

Canceled. Nothing to see here.

PRO
Synthiam
#4  

Why did you delete the last script?

#5  

Thanks DJ. Actually I did not realize the script wasn't working correctly. It would run and respond with different characters and responses. I did think over time that I really didn't get enough responses from the Dr Smith section though. I really want to get this converted and will be studying and working on it soon. In the mean time I guess I need to look at the problem you found and get it fixed. LOL. Thanks!

PRO
Synthiam
#6  

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.

revised: revised script 1.txt

But, that's the old version of teh script you uploaded so i dunno to do now.

#7  

@DJ,

Quote:

"Why did you delete the last script?"
Woops, I couldn't see it on my side. I thought it didn't post for some reason. I'll try again.

#8   — Edited

Here's a second long EZ Script I want to work on converting to JavaScript. It's the same impersonation skit but only runs once with one character's impression but selects randomly. Foy your approval and amusement. LOL:

Hahah here's your code as a file: SAVE FILES INSTEAD OF GIANT PASTES.txt