Asked — Edited
Resolved Resolved by Dunning-Kruger!

Random Personality Script Not Running

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 ARC software and this is running in a script manager. Thanks for any help you can provide.


# 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


ARC Pro

Upgrade to ARC Pro

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

#1  

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 ARC seems to be liking it better like this.


: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)

PRO
Synthiam
#2  

I won't tell you the solution right away - but i'll ask questions to help you solve it..

Q. Where does $QuestionsAnswer get set to a value, ever?

#3  

It gets set by voice recognition.
When someone says Yes, it gets set to "Yes", and when someone says no, it gets set to "no". The parameter is created during the startup script and is initially set to "".

here is the startup script


$x = 0
$lastDay = $day
$batteryLEDs = "BlinkLights"
$rsstext = ""
$QuestionAnswer = ""
# battery monitor
ControlCommand("Camera", CameraStop)
ControlCommand("Radar Scan", PauseOn)
ControlCommand("Light", PauseOn)
ControlCommand("RightEdge Detection", PauseOn)
ControlCommand("LeftEdgeDetection", PauseOn)
ControlCommand("Floor Map", PauseOn)
ControlCommand("Soundboard", Stop)
ControlCommand("Battery Cell 1", PauseOn)
ControlCommand("Compass", PauseOn)
ControlCommand("Battery Cell 2", PauseOn)
ControlCommand("Temp", PauseOn)
  #set decent voice
  ControlCommand("Speech Settings", SetVoice, "Microsoft Hazel Desktop")
  ControlCommand("Speech Settings", SetVoiceAge, "Teen")
  ControlCommand("Speech Settings", SetVoiceEmphasis, "Strong")

  #Start monitoring temp
  ControlCommand("Script Manager", ScriptStart, "MonitorTemps")
  ControlCommand("Script Manager", ScriptStart, "MonitorLight")
  #Play wakeup sound
  ControlCommand("Soundboard", Track_13)

  # arms 
  servo(d8, 24)
  servo(d9, 72)
  servoSpeed(d8, 2)
  servoSpeed(d9, 2)

  # head
  servo(d6, 32)
  servo(d7, 56)
  servoSpeed(d6, 2)
  servoSpeed(d7, 2)

  # camera power
  set(d19, on)

  controlcommand("camera", cameraservotrackenable)
  controlcommand("camera", cameramovementtrackdisable)
  controlcommand("Camera", cameraview)

  #controlCommand("Personality Generator", pauseoff)
  ControlCommand("Script Manager", ScriptStart, "Personality Generator")

  controlCommand("Speech Recognition", PauseOff)
  
ControlCommand("Script Manager", ScriptStart, "BatteryMonitor")
if ($batteryLEDs = "BlinkLights")
  say("There is an issue with the battery.  Please correct.")
  stop()
elseif ($batteryLEDs = "LightsOff")
  say("Battery power is very low.  Please put in a new battery.")
  stop()
else
endif

# This must be at end of script because 
# the command will stop even this script
# ControlCommand("Script Manager", ScriptStopAll)

#5  

Still an issue. When I run the script with the elseif commands, I get this Start 1: :GeneratePersonality 3: $personality = GetRandom(0,19) 5: If($personality = 0) 85: endif 86: SleepRandom(10000,60000)

This is the script I am using to get these results.


:GeneratePersonality
$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($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
$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
SleepRandom(10000,60000)
goto(GeneratePersonality)

$Personality = 12. Why is it stopping at line 5 and not making it to the elseif in line 8 or any of the others.

When running with just if statements, it gets through the script showing all like numbers like this. Start 1: :GeneratePersonality 3: $personality = GetRandom(1,20) 4: print($personality) > 17 6: If($personality = 1) 8: endif 10: If($personality = 2) 12: endif 14: If($personality=3) 15: endif 17: If($personality = 4) 18: endif 20: If($personality = 5) 21: endif 23: If($personality = 6) 24: endif 26: If($personality = 7) 27: endif 29: If($personality = 8) 30: endif 32: If($personality = 9) 33: endif 35: If($personality = 10) 55: endif 57: If($personality = 11) 60: endif 62: If($personality = 12) 63: endif 65: If($personality = 13) 66: endif 68: If($personality = 14) 69: endif 71: If($personality = 15) 72: endif 74: If($personality = 16) 75: endif 77: If($personality = 17) 78: endif 80: If($personality = 18) 81: endif 83: If($personality = 19) 90: endif 92: If($personality = 20) 93: endif 95: SleepRandom(10000,60000)

This is the script I am using for these results


: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)


#6  

Might not make any difference whatsoever, but maybe try using GetRandomUnique(1,20) instead...? I also noticed you use random numbers 0,19 with the script using elseif and 1,20 with using just the "if" statements... maybe it is the 0 value as a random# that is giving you the problem...?

PRO
Synthiam
#7  

how does the $QuestionsAnswer get data from the "speech recognition"? What command is populating the value to $QuestionsAnswer from speech recognition?

Do you think WaitForChange() is populating $QuestionsAnswer from speech recognition? :)

You're almost there!

#8  

Bingo.... found your problem! Drop your linen and start your grin'in ..... your variable $QuestionsAnswer.... look closely at it..... ;)....DJ you're too funny....

#9  

If you are implying that the issue is with the variable $QuestionsAnswer having the "s" between "$Question" and "Answer", I corrected that silly mistake. Thanks DJ for finding that. It would have driven me crazy, but that isn't the issue that I am seeing.

To try to get to the bottom of what is going on, I did this.


:GeneratePersonality
$personality = GetRandom(0,2)
print($personality)
If($personality = 0) 

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

ElseIf($personality = 2)
ControlCommand("Script Manager", ScriptStart, "SayRandomFact")
else
endif
SleepRandom(1000,2000)
goto(GeneratePersonality)

This works.

However, when I change the script to this


:GeneratePersonality
$personality = GetRandom(0,2)
print($personality)
If($personality = 0) 
  #Breaking The Script

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

ElseIf($personality = 2)
ControlCommand("Script Manager", ScriptStart, "SayRandomFact")
else
endif
SleepRandom(1000,2000)
goto(GeneratePersonality)

The script breaks. It looks like there is an issue with placing #comments inside of an if statement?

#10  

It's not the # in the elseif I think that's the problem. I think you need some code after each "if" and "elseif" statement... Your code didn't work for me either until I threw in a print("anything here") command after each if and elseif statement... It then worked as expected... Ignore the smilely face, it's a known bug on the webpage... supposed to be a close bracket

#11  

Thanks Richard!

I was using those as place fillers but replaced them with Say("the description") until I could script each section. This works.

Have a great day!

#12  

Hey, you're welcome... This helped me learn as well, because I didn't know this until just now either...

PRO
Synthiam
#13  

That was going to be my next item to get you to look at. You can't have an empty IF or ELSEIF because it's an empty instruction. It needs at least something in there.. Otherwise it assumes the ELSEIF is from a different nest in the stack.

Back to the first problem i'm helping you identify. It had nothing to do with the variable name spelling (although I didn't catch that and you did).

I'd like you to tell me what you think the command WaitForChange() does and how it pertains to Speech Recognition...

#14  

Ok, looks like I am in this too.... Hmmm... WaitForCange() I am also trying to grasp what you are getting at with it, DJ..... I too am missing something here and I really want to learn why...

As a side note... One thing great about what you have created here with ARC is software that is easy enough to initially grasp, yet can take a lifetime to master... This way it keeps you hooked because learning is ongoing.... ARC can match a persons abilities and knowledge as you learn... And no, I haven't had any beer (yet) today... Just lamenting on how much I have learned programming wise since I stated using ARC about 8 months ago.... Learned more in that time frame then I did in the last 10 years of this hobby...

#15  

sorry about that. well, I is waiting for a variable to change.

What happens in the script is the robot asks a question. It then waits for the variable to change. The voice recognition section sets the variable to yes or no depending on the response, thus changing the variable and allowing this script to then evaluate the variable and continue based on the value of the variable. That's what it's doing and how it is working anyway. Do I understand this correctly?

PRO
Synthiam
#16  

Can you post the code on the Speech Recognition Section that changes the variable based on the speech input?

#17  

yes $QuestionAnswer = "yes" no $QuestionAnswer = "No"

I will post my entire solution to the cloud as public if that helps.

#18  

posted it to incomplete bots, called Wall-e_Full-dcochran

PRO
Synthiam
#19  

Can you post the piece of code that assigns the values to the $QuestionAnswer from the speech recognition?

#20  

all it does, in the voice recognition section is a single line for yes and for no. The box looks like this

Phrase | Command -----------------+----------------------------------- Yes | $QuestionAnswer = "yes" -----------------+--------------------------------- No | $QuestionAnswer = "No" -----------------+----------------------------------

drawn in asci for those of us that remember BBS systems :)

PRO
Synthiam
#21  

Roger that, okay!

That was my biggest concern is because no where in the code you pasted is the variable changed.

Keep in mind that every time the personality script runs, the variable will equal the last value. If you said YES last time, and say YES again - the WaitForChange() will never stop.

I would recommend clearing the variable at the top of the script. Set the variable to = "" at the top of the script.

#22  

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.

PRO
Synthiam
#23  

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 :)


: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)

#24  

@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. ;)

United Kingdom
#25  

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.

#26  

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 :)