Canada
Asked — Edited
Resolved Resolved by Rich!

Help Needed Converting This Script From Python To Ez-Script

I have switched my robot over to Ez-Robot and I need some help converting the following Python script over the EZ-Robot language.

if (data == "lets do some math"): math()

if (data == "one"):
      one()
      global first
      first += 1
      print(first)

if (data == "two"):
      two()
      global first
      first += 2
      print(first)

if (data == "three"):
      three()
      global first
      first += 3
      print(first)

if (data == "four"):
      four()
      global first
      first += 4
      print(first)

if (data == "five"):
      five()
      global first
      first += 5
      print(first)

if (data == "add one"):
      plusone()
      global second
      second += 1
      print(second)

if (data == "add two"):
      plustwo()
      global second
      second += 2
      print(second)

if (data == "add three"):
      plusthree()
      global second
      second += 3
      print(second)

if (data == "add four"):
      plusfour()
      global second
      second += 4
      print(second)

if (data == "add five"):
      plusfive()
      global second
      second += 5
      print(second)

if (data == "what does that equal"):
      equals()
      global number
      number = (first+second)
      i01.mouth.speak(str(first) + "plus" + str(second) + "is" + str(number))
      global first
      first = (first + second)
      global second
      second = 0

if (data == "start over"):
      i01.mouth.speak("OK")
      rest()
      sleep(2)
      i01.mouth.speak("ready")
      global first
      first = 0
      global second
      second = 0
      print("starting from 0")

It's a script where the robot does addition. Can anyone help me out with this, thanks


ARC Pro

Upgrade to ARC Pro

Take control of your robot's destiny by subscribing to Synthiam ARC Pro, and watch it evolve into a versatile and responsive machine.

#1  

I'm doing the same thing. Instead of using Def Test() , you open a script window in EZ-B and name it.

Then in your main script you click on the Cheat Sheet icon and you'll find the script Test() .Click on it and it will automatically get inserted into your main script.

You can also do this with any controls, camera , motion control etc.

As your main script runs if a condition you set is true, it will go to that control or script that you wrote, run and then return to your main script.

Hope this helps

#2  

@mtiberia Thanks for getting back to me. Can you give me a bit more information, I don't quite understand what you mean. Thanks

#3  

this is the main program

if then condition for Script one

ControlCommand("Script_1", ScriptStart) Sleep(1000)

if then condion for Script two

ControlCommand("Script_2", ScriptStart) Sleep(1000)

Say(" I'm back in the main program")

Print("done")

You have three EZ Script controls named , main program, Script_1, and Script_2

#4  

I don't know how the smiley faces got there but their suppose to be closing brackets.

#5  

You could do it that way or you could leave it in one script. You could also use goto statements to jump to different labels in your script. Lots of ways to accomplish this, but it is best for you to attempt it and ask specific questions about an issue than to have someone convert it for you.

United Kingdom
#6  
if (data == "lets do some math"):
math()

The IF statement is similar however it depends where it gets the data from. All variables need to be marked as variables with the $ symbol so in this case it would be $data. Not 100% sure what == means in python (I dislike python so seldom use it). If it just means equals then the IF statement would be like so;

IF($data = "lets do some math")

I presume math() calls a sub routine. So, as others have said there are a few ways to do this. Individual scripts or labels, gotos and returns. The label method would be;

IF($data = "lets do some math")
  Goto(math)
EndIF

:math
# Sub Routine
Return()

The rest of the script would follow suit. Variables with a $ before it's name. Goto() for sub routines (or ControlCommand() if you want to start other scripts).

That's as much re-writing as I'm likely to do as I prefer to make people work it out themselves by pointing them in the right direction.

Read over the EZ-Script manual and see which commands look like they match the python commands.

#7  

Thanks Rich, that's got me going now. I'll work on it and probably have more questions later.

#8  

Ok, I've got this far;

$x = "first number" $y = "second number" $x + $y = "number"

If($x = "one")

ElseIf($y = "add two")

ElseIf($x + $y = "number") Print("$x + $y = "number") ENDIF

So with the verbal commands ( "one" and "add two") I am trying to get it to say three. A little help needed.

Thanks