Canada
Asked — Edited
Resolved Resolved by JustinRatliff!

New Help With This Script

I am looking for a little help to finish off this script. The script as it is works, however, I want it to speak the sum of the 2 numbers. I have tried a few different ways but I can't get it. Hey, I pretty proud of getting this far with it. I've made a comment in the code of what I want it to say.


:start
$heard = "speech"
WaitForChange($heard)
if($Heard = "won")
$x = 1
Say("one")
elseif($heard="two")
$x = 2
Say("two")
endif

WaitForChange($heard)
if($heard = "plus one")
$y = 1
Say("plus one")
elseif($heard = "plus two")
$y = 2
Say("plus two")
#print($x + $y)
EndIf

WaitForChange($heard)
if($heard = "what does that equal")
#This is where I want it to say something like "$x plus $y equals the sum" or 
for example "1 plus 2 equals 3" (if those were the numbers it heard)
print($x + $y)
Endif
GoTo(start)

As always any help is appreciated, Thanks


ARC Pro

Upgrade to ARC Pro

Stay at the forefront of robot programming innovation with ARC Pro, ensuring your robot is always equipped with the latest advancements.

#1  

Are you using WaitForSpeech somewhere in another script? After the WaitForChange you have only 2 choices... I think you need a 3rd so in case the waitforchange does not get either of your response's it immediately skips back to start.... No sense going further and getting stuck on the next waitforchange


:start
$heard = "speech"
WaitForChange($heard)
if($Heard = "won")
$x = 1
Say("one")
elseif($heard="two")
$x = 2
Say("two")
else
say("sorry, didn't hear your response correctly")
GoTo(start)
endif

WaitForChange($heard)
if($heard = "plus one")
$y = 1
Say("plus one")
elseif($heard = "plus two")
$y = 2
Say("plus two")
#print($x + $y)
else
say("sorry, didn't hear your response correctly")
GoTo(start)
EndIf

WaitForChange($heard)
if($heard = "what does that equal")
$answer= $x + $y
Saywait($x + " plus " + $y + " equals  " + $answer)
print($x + $y)
Endif
GoTo(start)

#2  

This is how I would do it:


$sum = Abs($x + $y)
Say($x + " plus " + $y + " equals the sum " + $sum)

Abs is the math function and you can do basic math with it like add, subtract, multiple and divide.

#3  

I shouldn't have posted this thread so late at night - The title should have read "Need help with this script", anyway, you guys understood what I meant. @JustinRatliff Thanks that worked. I was so close once. @Richard R Thanks, Ya I have to put what you suggested in the script. I'm building it step by step, there's lots more to go in to it.

#5  

@bhouston.... No problem ... I am sure I will be asking you question here and there about your inmoov build... I have just taken the plunge and begun building my own.... Speaking of questions... here is a quick one.... Are you using the HK15298 servos in the forearms for the fingers and wrist rotate?

#6  

@Richard R I used HS-311 and MG996R for the fingers and wrists. They were readily available. Email anytime at houston5913@hotmail.com If you have questions and don't want to post them here.

#8  

I am writing some math scripts, I've got addition and subtraction figured out . For multiplication I've tried -


$x=2
$Y=2
print ($x x $y)

Doesn't like the "x" in there. What symbols should I use for multiplication and division. Thanks

#9  

I copy and pasted your above example and for some reason you're right it didn't work... I then erased it and just typed in this time and it worked... Something about copy and pasting code from the forum into scripts that causes problems I guess...

#10  

It worked? I get this when I run it;


Start
1: $x=2
2: $Y=2
4: print ($x x $y)
> Error on line 4: Missing String Quotes or Invalid Expression: x
Done (00:00:00.1696435)

#11  

Ooops I see you are multiplying not adding... use the * symbol instead of x....

#13  

That's what I needed thanks.

#14  

Here is the code I use to allow the robot to play math game with my 4 year old.

this example limits the answer to 1 to 10 for her age.


$firstnumber = Getrandom(0,5)
$secondnumber = getrandom(0,5)
$answer = $firstnumber + $secondnumber
:loop
sayezb("what is " + $firstnumber + " plus " + $secondnumber )
sleep(3000)
$response = WaitForSpeech(50, "1","2","3", "4","5","6", "7","8","9","0","10")
sayezb("you said" + $response)
if ($response  == $answer ) 
sayezb("Good job! Yes " +  $answer + " is the correct answer")
else
Sayezb("Sorry " + $response + " is not correct. please try again.")
sleep(3000)
goto(loop)
endif


This is very interactive an she has a blast playing this with the robot.

I will modifiy this soon as we have sayezbwait()

#15  

Thanks, that's great. My granddaughter will love that!

#16  

@ Luis, Is there an email I can contact you at? or will you please contact me at houston5913@hotmail.com.

Thanks Bob

#17  

@ Luis, How would you make your math game script to go higher on addition? Let say up infinity? Thanks

United Kingdom
#18  

Up to infinity is a pretty much impossible task however by changing the GetRandom() commands you would change how high it goes.

Check the EZ-Script manual for the syntax and explanation of the GetRandom() command, it explains how to use it.

#19  

What is making it print? I don't see a print command

#20  

This script doesn't print anything. It takes two numbers and adds them. Then asks you the question and waits for your response. If your response matches the answer, then it tells you that you are correct. If you are wrong, it tells you that you are wrong and asks you to try again. This is if you were talking about the one above from Luis.