Community Question

I cant seem to get this script to do anything other than to assign a random number to the $personality variable. When I run the script, it changes the variable and does nothing. I have been watching the variable change and it does hit 1, 2, 10 and 19 but nothing fires from there. Does anyone see anything wrong with the script? I am on version 2014.5.27 of the ez-builder software and this is running in a script manager. Thanks for any help you can provide.

Code:


# Get a response value
$personality = GetRandom(0,19)

If($personality = 0)
# dance

ElseIf($personality = 1)
ControlCommand("Script Manager", ScriptStart, "TellMeAJoke")

ElseIf($personality = 2)
ControlCommand("Script Manager", ScriptStart, "SayRandomFact")

ElseIf($personality = 3)
# ask if anyone else is getting hungery

ElseIf($personality = 4)
# Call Maples name and start autonimous movement

ElseIf($personality = 5)
# make a huge expression then look down with your arms hung low.

ElseIf($personality = 6)
#check the temp and if it is hot or cold, make a comment about it

ElseIf($personality = 7)
#Act like you are reading

ElseIf($personality = 8)
#look up and find someone, identify them, and ask how they are doing today.

ElseIf($personality = 9)
#see if it dark and if so, see if it is after 9 PM. if so, ask if it is bedtime

ElseIf($personality = 10)
Say("Can I chase the ball?")
:ChaseBall
WaitForChange($QuestionsAnswer)
if ($QuestionAnswer = "yes")
ControlCommand("Script Manager", ScriptStart, "ChaseColor")
Elseif ($QuestionAnswer = "no")
#look sad
else
say("I did not hear you. Can I chase the ball?")
endif
If($QuestionAnswer = "")
Goto(ChaseBall)
endif
$QuestionAnswer = ""

ElseIf($personality = 11)
say("Did you know it is ")
ControlCommand("Script Manager", ScriptStart, "SayTime")

ElseIf($personality = 12)
#autonomous collision avoidance

ElseIf($personality = 13)
#look mad and play mad sound

ElseIf($personality = 14)
#sway from side to side and play song

ElseIf($personality = 15)
#find someone and wave at them

ElseIf($personality = 16)
#look sad and say eve

ElseIf($personality = 17)
#scratch head - Thinking

ElseIf($personality = 18)
#Raise arms and gears
#Make yawn sound

ElseIf($personality = 19)
#look up and find someone
ControlCommand("Script Manager", ScriptStart, "FollowMotion")
ControlCommand("Soundboard", Track_4)
ControlCommand("Script Manager", ScriptStart, "kiss")
Left(255,1000)
Right(255,1000)
else
endif

CochranRobotics
Commented May 2014
It looks like the there may be an issue with elseif. I rewrote this as follows and it seems to be working. I haven't checked all of the personalities yet, but EZ-Builder seems to be liking it better like this.

Code:


:GeneratePersonality
# Get a response value
$personality = GetRandom(1,20)
print($personality)

If($personality = 1)
ControlCommand("Script Manager", ScriptStart, "TellMeAJoke")
endif

If($personality = 2)
ControlCommand("Script Manager", ScriptStart, "SayRandomFact")
endif

If($personality=3)
endif

If($personality = 4)
endif

If($personality = 5)
endif

If($personality = 6)
endif

If($personality = 7)
endif

If($personality = 8)
endif

If($personality = 9)
endif

If($personality = 10)
Say("Can I chase the ball?")
:Ball
WaitForChange($QuestionsAnswer)

if ($QuestionAnswer = "yes")
ControlCommand("Script Manager", ScriptStart, "ChaseColor")

Elseif ($QuestionAnswer = "no")
#look sad

else
say("I did not hear you. Can I chase the ball?")

endif

If($QuestionAnswer = "")
Goto(Ball)
endif
$QuestionAnswer = ""
endif

If($personality = 11)
say("Did you know it is ")
ControlCommand("Script Manager", ScriptStart, "SayTime")
endif

If($personality = 12)
endif

If($personality = 13)
endif

If($personality = 14)
endif

If($personality = 15)
endif

If($personality = 16)
endif

If($personality = 17)
endif

If($personality = 18)
endif

If($personality = 19)
#look up and find someone
ControlCommand("Script Manager", ScriptStart, "FollowMotion")
ControlCommand("Soundboard", Track_4)
ControlCommand("Script Manager", ScriptStart, "kiss")
Left(255,1000)
Right(255,1000)
endif

If($personality = 20)
endif

SleepRandom(10000,60000)
goto(GeneratePersonality)

CochranRobotics
Commented May 2014
There is a chunk after the variable is evaluated and the robot does what it is going to do that it sets this variable back to ""

Thanks for digging into this so much DJ. I do really appreciate it.
DJ Sures
Commented May 2014
oops I didn't fix the missing code within the IF conditions for you. Here is the working proper code... You always need something in the IF or ELSEIF or ELSE condition. You can't have a condition that is empty, otherwise it doesn't make logical sense to the stack. You need to always have something in there. More than just a comment. Programming is a logical execution of commands, it's pretty straight forward. The challenge is identifying the order of those commands. But having empty commands doesn't make logical sense :)


Code:


:GeneratePersonality

$QuestionAnswer = ""

$personality = GetRandom(0,19)

IF ($personality = 0)

say($personality)

ELSEIF ($personality = 1)

ControlCommand("Script Manager", ScriptStart, "TellMeAJoke")

ELSEIF ($personality = 2)

ControlCommand("Script Manager", ScriptStart, "SayRandomFact")

ELSEIF ($personality = 3)

say($personality)

ELSEIF ($personality = 4)

say($personality)

ELSEIF ($personality = 5)

say($personality)

ELSEIF ($personality = 6)

say($personality)

ELSEIF ($personality = 7)

say($personality)

ELSEIF ($personality = 8)

say($personality)

ELSEIF ($personality = 9)

say($personality)

ELSEIF ($personality = 10)

Say("Can I chase the ball?")

:ChaseBall

WaitForChange($QuestionAnswer)

IF ($QuestionAnswer = "yes")

ControlCommand("Script Manager", ScriptStart, "ChaseColor")

ELSEIF ($QuestionAnswer = "no")

# look sad

ELSE

say("I did not hear you. Can I chase the ball?")

ENDIF

IF ($QuestionAnswer = "")

Goto(ChaseBall)

ENDIF

ELSEIF ($personality = 11)

say("Did you know it is ")
ControlCommand("Script Manager", ScriptStart, "SayTime")

ELSEIF ($personality = 12)

say($personality)

ELSEIF ($personality = 13)

say($personality)

ELSEIF ($personality = 14)

say($personality)

ELSEIF ($personality = 15)

say($personality)

ELSEIF ($personality = 16)

say($personality)

ELSEIF ($personality = 17)

say($personality)

ELSEIF ($personality = 18)

say($personality)

ELSEIF ($personality = 19)

# look up and find someone
ControlCommand("Script Manager", ScriptStart, "FollowMotion")
ControlCommand("Soundboard", Track_4)
ControlCommand("Script Manager", ScriptStart, "kiss")
Left(255,1000)
Right(255,1000)

ELSE

say($personality)

ENDIF

SleepRandom(1000,6000)

goto(GeneratePersonality)

Dave Schulpius
Commented May 2014
@DJ said; "Programming is a logical execution of commands". Humm, I must be too much in touch with my feminine side and that's why I sometimes struggle with writing code that works. :P

Sorry gals. ;)
Rich
Commented May 2014
lol Dave.
If only women were logical... that may explain why I struggle to understand them most of the time :) The EZ-Script GetRandom() comes to mind whenever a woman gives an answer... Except for the Canadian ones of course (and any others who lurk in here but don't post)

This also gave me the opportunity to post and receive notifications without answering the issues. I am loving this topic as this is the way people learn most in my experience.


As a side note though, and it's probably just me but I prefer to assign variables with at least something to them rather than a $variable = "". Usually when I reset a variable I use $variable = "null". More than likely this is just me and my OCD but I don't like a variable to be empty.
chrissi
Commented May 2014
Rich and Dave, I often get accused of being too logical :) I'm not the only girl like this. Lol.

I don't think it's so much about being a girl, it's just your personality as molded by environmental and genetic pressures :)
Question
AvatarCochranRobotics
Asked on Wednesday, May 28, 2014