Award
Congratulations Rich, for answering the question and has received an EZ-Credit award! Share what you have learned and create a tutorial to help others by clicking here.

Help Needed Converting This Script From Python To Ez-script

Assistance Requested

Help bhouston with their question and receive $10 of EZ-Credit to get more robots and parts from our store. The following information was provided about their previous efforts searching tutorials for a resolution.

bhouston claims to have checked these sources:
 
#1

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

I have found a few conversations, tutorials and activities that may help with your question. Take a look at these links. I've sorted them by what I believe to be most relevant but that is not always the case as I'm still learning.


Also, consider reviewing the Learn section for informative lessons and activities. Check it out!


#2

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

#3

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

#4

# 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"Winky


Print("done"Winky



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

#5

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

#6

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.

#7

Code:

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;

Code:

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;

Code:

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.

#8

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

#9

Ok, I've got this far;

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


If($x = "one"Winky

ElseIf($y = "add two"Winky

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

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

Thanks

#10

What's up with the Smile ?