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

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

#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

#10  

Still working on it, when I run the script it says "false" - progress!


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

$data = "let's do some math"
$data = "what does that equal"

If ($data = "let's do some math")
ControlCommand("Auto Position", AutoPositionFrameJump, "Ready")
EndIf

If($x = "one")
ControlCommand("Auto Position", AutoPositionAction, "one")

ElseIf($y = "add two")
ControlCommand("Auto Position", AutoPositionAction, "add two")
ElseIf($x + $y = "number")
EndIf
If ($data = "what does that equal")
Sayezb("$x" + "$y" = "number")
#Sayezb("first number" + "second number" = "number")
ENDIF

#ClearVariables


#11  

Sayezb("$x" + "$y" = "number")

sure the variables should be in quotes?

United Kingdom
#12  

@bhouston, the sooner you forget everything about other languages the easier it will become. Your code above, as far as EZ-Script is concerned, doesn't make much sense.

EZ-Script is script. It will follow it line by line. Where you set the variable $data on line 5 and 6, line 5 is pretty much redundant as it immediately changes to what it's set as in line 6.

Also, "$x + $y =" is not valid.

Where does $x come from? Your IF checks against $x yet it's set to "first number" at the start of the script, nothing changes it from that.

To be honest there is a lot wrong with the script and very little that is right. Read through the EZ-Script manual, follow the EZ-Script tutorial and check out some other projects scripts from the cloud and the examples folder in ARC. For variables and IFs etc. check out the Introduction To Scripting topic I wrote some time ago, while there may have been some minor syntax changes since (possibly) it was minimal and pretty much limited to requiring quotes around strings.

#13  

@ Rich, as you can see, I am not a script "writer", I am more of a script "user". Once having script that is similar to what I want, I can manipulate it to meet my needs. Having said that it is my goal to become a script "writer", however, it will be a long road. I am reading what you suggested.

Backing up to my first post;

if (data == "lets do some math"): is "heard data" from a voice command. In your "Introduction to Scripting" is see how to add input from a sensor but I'm not clear on how you add input from a voice command into a variable.

Thanks

#14  

There is a sample project that I put out on the cloud a while back that might help you. I am busy with work this week so I wont have much time to help, but this should help you get an idea of what needs to be done.

:D my wall-e

There is a script called something like personality. It will help with scripting.
There is one called Init that will help you setup your variables. There is a voice recognition command that is yes. it will help show you how to set a variable based on a voice command.

There is a lot more in there but these 3 things should help you get moving.

#15  

The name of the script is Personality Generator

if you look at personality 10, you will see the WaitForChange command that you will need to use. It also shows how to use labels and goto.

United Kingdom
#16  

Look up the WaitForSpeech() command in the EZ-Script manual and check out the example for WaitForSpeech() in the ARCs examples. Both should help you answer your own question (hopefully).

If not, come back and ask again and I'll give you some more help.:)

#17  

@ Rich and @ d.cochrane Thanks for your help with this. I should mark this resolved but I don't know who to give it to. You have both given me something to use in my quest to get this script working with Ez-Robot. What to do?

#18  

I think that Rich and I are about the same in that we help just to help. I dont think either of us care about who gets credit. its just good that we can help some.

#19  

I've been prompted to mark this resolved. I could use some more help to get me going, so I'll leave it active for a couple more days, just in case someone has anymore thoughts on it.

United Kingdom
#20  

For the record, if there's ever any question of who to give credit to between me and anyone else, give it to the other guy (unless I've provided more help that is). At this point I'd like to think that almost 300 questions answered I can let a few slide when it's close.

Which part do you need more help on?

I only quickly read over the above again but it looks like you want to use WaitForSpeech()

This will hold the script until the command is spoken.

Use that spoken command to set a variable or in an IF statement to trigger commands or responses.

Or use the speech recognition control for speech commands. When one is spoken have that trigger a script or control or sequence of events using ControlCommand()

#21  

Thanks for everyone's help. I'll have more questions I'm sure,