Award
Congratulations Richard R, 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.

I Need Help Figuring Out This Scripting Question

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 a few scripts that don't do what they are suppose to do until I run thru them once.
Let me explain that - in the script below the robot is doing addition. What should happen is, for example, when I say "two" the robot should look at it's hand, extend 2 fingers and say "two" and when I say "plus four" the robot should look at it's other hand, extend 4 fingers and say "add four". What is happening is the robot is looking where it should and saying what it should but not extending the fingers. It does the addition part correctly and returns to the start of the script. Then given the commands again everything runs properly. It may be something I'm doing in my scripting because this happens in a couple of other scripts I have written.
I would appreciate any thoughts on how to solve this problem.
Thanks

Code:




Sayezb("ok, I like doing math")


sleep(500)

ControlCommand("Script Manager", ScriptStart, "Do math")

sleep(4000)

sayezb("ready")

:start

$heard = "speech"

WaitForChange($heard)

if($Heard = "one")

$x = 1

elseif($heard="two")

$x = 2

elseif($heard ="three")

$x = 3

elseif($heard = "four")

$x = 4

elseif($heard = "five")

$x = 5


endif



WaitForChange($heard)

if($heard = "plus one")

$y = 1

elseif($heard = "plus two")

$y = 2

elseif($heard ="plus three")

$y = 3

elseif($heard ="plus four")

$y = 4

elseif($heard = "plus five")

$y = 5

#print($x + $y)

endif





WaitForChange($heard)

if($heard = "what does that equal")

servo(d0,150)

servospeed(d0,3)

servo(d1,90)

servospeed(d1,3)

sayezb("ummm")


ControlCommand("Script Manager", ScriptStart, "Close right Hand")

ControlCommand("Script Manager", ScriptStart, "Close left hand")

Sleep(1500)

Servo(d0,116)

servospeed(d0,3)

servo(d1,118)

servospeed(d1,3)

sleep(1500)

$sum = Abs($x + $y)

Sayezb($x + " plus " + $y + " equals " + $sum)

endif





if($sum = 2)

ControlCommand("Script Manager", ScriptStart, "equals two")

elseif($sum = 3)

ControlCommand("Script Manager", ScriptStart, "equals three")

elseif($sum = 4)

ControlCommand("Script Manager", ScriptStart, "equals four")

elseif($sum = 5)

ControlCommand("Script Manager", ScriptStart, "equals five")

elseif($sum = 6)

ControlCommand("Script Manager", ScriptStart, "equals six")

elseif($sum = 7)

ControlCommand("Script Manager", ScriptStart, "equals seven")

elseif($sum =8)

ControlCommand("Script Manager", ScriptStart, "equals seven")

elseif($sum = 9)

ControlCommand("Script Manager", ScriptStart, "equals nine")

elseif($sum = 10)

ControlCommand("Script Manager", ScriptStart, "equals ten")

endif



sleep(4000)

ControlCommand("Script Manager", ScriptStart, "Close right Hand")

ControlCommand("Script Manager", ScriptStart, "Close left hand")

Sleep(500)



GoTo(start)

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

Hey Bob. I assume that the scripts called equal two and equal three and so on are used to extend the fingers on a certain hand. I also assuming that equal seven extends 5 fingers on one hand and two on the other hand.

What I think you need are scripts like "left two" which would extend 2 fingers on the left hand and say "right two" which would extend two fingers on the right hand. In your script, when you say two, in your if statement, you would call the "left two" script. Later in your script, when you catch you saying plus two, you would call the "right two" script. The rest of the script is doing what you want so there is no need for changes.

#3

This is assuming that you are looking at the left hand first, but it is easy to change once the other scripts have been made.

Code:






Sayezb("ok, I like doing math")


sleep(500)

ControlCommand("Script Manager", ScriptStart, "Do math")

sleep(4000)

sayezb("ready")

:start

$heard = "speech"

WaitForChange($heard)

if($Heard = "one")

$x = 1
ControlCommand("Script Manager", ScriptStart, "Left One")
elseif($heard="two")

$x = 2
ControlCommand("Script Manager", ScriptStart, "Left Two")
elseif($heard ="three")

$x = 3
ControlCommand("Script Manager", ScriptStart, "Left Three")
elseif($heard = "four")

$x = 4

elseif($heard = "five")

$x = 5


endif



WaitForChange($heard)

if($heard = "plus one")

$y = 1
ControlCommand("Script Manager", ScriptStart, "Right One")

elseif($heard = "plus two")

$y = 2
ControlCommand("Script Manager", ScriptStart, "Right Two")

elseif($heard ="plus three")

$y = 3
ControlCommand("Script Manager", ScriptStart, "Right Three")

elseif($heard ="plus four")

$y = 4

elseif($heard = "plus five")

$y = 5

#print($x + $y)

endif





WaitForChange($heard)

if($heard = "what does that equal")

servo(d0,150)

servospeed(d0,3)

servo(d1,90)

servospeed(d1,3)

sayezb("ummm")


ControlCommand("Script Manager", ScriptStart, "Close right Hand")

ControlCommand("Script Manager", ScriptStart, "Close left hand")

Sleep(1500)

Servo(d0,116)

servospeed(d0,3)

servo(d1,118)

servospeed(d1,3)

sleep(1500)

$sum = Abs($x + $y)

Sayezb($x + " plus " + $y + " equals " + $sum)

endif





if($sum = 2)

ControlCommand("Script Manager", ScriptStart, "equals two")

elseif($sum = 3)

ControlCommand("Script Manager", ScriptStart, "equals three")

elseif($sum = 4)

ControlCommand("Script Manager", ScriptStart, "equals four")

elseif($sum = 5)

ControlCommand("Script Manager", ScriptStart, "equals five")

elseif($sum = 6)

ControlCommand("Script Manager", ScriptStart, "equals six")

elseif($sum = 7)

ControlCommand("Script Manager", ScriptStart, "equals seven")

elseif($sum =8)

ControlCommand("Script Manager", ScriptStart, "equals seven")

elseif($sum = 9)

ControlCommand("Script Manager", ScriptStart, "equals nine")

elseif($sum = 10)

ControlCommand("Script Manager", ScriptStart, "equals ten")

endif



sleep(4000)

ControlCommand("Script Manager", ScriptStart, "Close right Hand")

ControlCommand("Script Manager", ScriptStart, "Close left hand")

Sleep(500)



GoTo(start)

#4

@d. cochran Here's my script for "two" and "plus four"

two

Code:


$heard = "two"
Sayezb("two")

servo(d0,57)
servospeed(d0,4)
servo(d1,90)
servospeed(d1,4)
servo(d4,0)
servospeed(d4,0)
servo(d3,0)
servospeed(d3,0)



plus four

Code:


$heard ="plus four"
Sayezb("plus four")

servo(d0,57)
servospeed(d0,2)
servo(d1,135)
servospeed(d1,2)
Servo(d14,0)
servospeed(d14,0)
servo(d15,0)
ServoSpeed(d15,0)
servo(d16,0)
servospeed(d16,0)
servo(d17,0)
servospeed(d17,0)


Like I said everything works properly after the first time thru the script. It seems like it isn't "releasing" from the ControlCommand().

Code:


ControlCommand("Script Manager", ScriptStart, "Do math")



The other scripts I am having problems with, start with an Auto Position script.

#5

Question for you. Are you wanting there to be a response by the hand when you say "Two" and again when someone says "Plus Two"?

I dont see how the robot is extending 2 fingers in the script unless it is happening in another script that isn't provided. It may be that it is happening in another script which isn't started until later in the script.

It is also possible to stop scripts if one is hanging around causing you issues.
ControlCommand("Script Manager", ScriptStop,"TheScriptName"Winky

From what you are describing, it looks like its more of a matter of something happening in another script that isnt started early enough in this script.

Gotcha, after rereading your second post.

The "two" and "plus four" scripts are not being called from this script.

#6

It looks like these might be being called from the "Do Math" script. Post that one if you would.

#7

Are the Two and Plus four scripts launched from the Do Math script along with all of the other possible answers? If this is the case, it may just be that enough time isn't being given for the other scripts to all start. If this is what is happening, I would think that it would be far more efficient to only launch these when needed as in the example that I sent to you. There would be a lot less activity on the processor that EZ-Builder is running on as there would be 10 less processes for the processor to monitor.

#8

The "Do Math" script simply brings the arms and fingers into position. Each number has a script , like the ones I posted and are only called on when that number is heard.

#9

Are you using a WaitForChange($HEARD) there also or are you evaluating $x and $y?

#10

WaitForChange($HEARD)
I also tried ControlCommand("Script Manager", ScriptStop,"TheScriptName"Winky and that didn't make any difference.