Greece
Asked — Edited

Mulit Answer To A Question.

Heloo Forum :)

I don't remember if it is answered this question: I want to ask my robot somethink or told, for examble: Hello, and the robot answer with many ways 1: hello, 2:i already told you 3:..... I want to choose the robot his own answer between 3 or more answers that i write to script.

Can i?


ARC Pro

Upgrade to ARC Pro

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

United Kingdom
#1  

Yes.

Use the function GetRandom()

For instance;


# GetRandom (Min,Max)
$answer = GetRandom(1,3)

IF($answer = 1)
  SayWait("Answer 1")
ElseIF($answer = 2)
  SayWait("Answer 2")
ElseIF($answer = 3)
  SayWait("Answer 3")
EndIF

I did an example of multiple choices the robot can make in my Jarvis project a while ago when I had him choose the colour he was going to be.


# Colour chooser script for Jarvis self design

# Use voice recognition to ask Jarvis what colour he wants to be
# Use random numbers to choose a colour
# Run the choices until the same is picked twice consecutivly

# Colour options
$black = 0
$brown = 0
$red = 0
$orange = 0
$yellow = 0
$green = 0
$blue = 0
$violet = 0
$grey = 0
$white = 0
$silver = 0
$gold = 0


SayWait("Hummmm let me think")
Sleep(500)

$choice1 = GetRandom(0,11)
Goto(pick1)
SayWait("I quite like $colour")

:loop
$choice2 = GetRandom(0,11)
IF ($choice1 = $choice2)
  Goto(done)
ELSE 
  Sleep(300)
  Goto(pick2)
  IF ($black>3 OR $brown>2 OR $red>2 OR $orange>2 OR $yellow>2 OR $green>2 OR $blue>2 OR $violet>2 OR $grey>2 OR $white>2 OR $gold>2 OR $silver>2)
    goto(done)
  ELSE 
    $phrase = GetRandom(0,3)
    IF ($phrase = 0)
      SayWait("but I also like $colour")
    ELSEIF ($phrase = 1)
      SayWait("although $colour is nice")
    ELSEIF ($phrase = 2)
      SayWait("but theres something to be said about $colour")
    ELSEIF ($phrase = 3)
      SayWait("but $colour is cool")
    ENDIF 
  ENDIF 
ENDIF 
$choice1 = GetRandom(0,11)
IF ($choice1 = $choice2)
  Goto(done)
ELSE 
  Sleep(300)
  Goto(pick1)
  IF ($black>2 OR $brown>2 OR $red>2 OR $orange>2 OR $yellow>2 OR $green>2 OR $blue>2 OR $violet>2 OR $grey>2 OR $white>2 OR $gold>2 OR $silver>2)
    goto(done)
  ELSE 
    $phrase = GetRandom(0,3)
    IF ($phrase = 0)
      SayWait("but I also like $colour")
    ELSEIF ($phrase = 1)
      SayWait("although $colour is nice")
    ELSEIF ($phrase = 2)
      SayWait("but theres something to be said about $colour")
    ELSEIF ($phrase = 3)
      SayWait("but $colour is cool")
    ENDIF 
  ENDIF 
ENDIF 
Goto(loop)

:pick1
IF ($choice1 = 0)
  $colour="black"
  $black++
ELSEIF ($choice1 = 1)
  $colour="brown"
  $brown++
ELSEIF ($choice1 = 2)
  $colour="red"
  $red++
ELSEIF ($choice1 = 3)
  $colour="orange"
  $orange++
ELSEIF ($choice1 = 4)
  $colour="yellow"
  $yellow++
ELSEIF ($choice1 = 5)
  $colour="green"
  $green++
ELSEIF ($choice1 = 6)
  $colour="blue"
  $blue++
ELSEIF ($choice1 = 7)
  $colour="violet"
  $violet++
ELSEIF ($choice1 = 8)
  $colour="grey"
  $grey++
ELSEIF ($choice1 = 9)
  $colour="white"
  $white++
ELSEIF ($choice1 = 10)
  $colour="silver"
  $silver++
ELSEIF ($choice1 = 11)
  $colour="gold"
  $gold++
ENDIF 
Return()

:pick2
IF ($choice2 = 0)
  $colour="black"
  $black++
ELSEIF ($choice2 = 1)
  $colour="brown"
  $brown++
ELSEIF ($choice2 = 2)
  $colour="red"
  $red++
ELSEIF ($choice2 = 3)
  $colour="orange"
  $orange++
ELSEIF ($choice2 = 4)
  $colour="yellow"
  $yellow++
ELSEIF ($choice2 = 5)
  $colour="green"
  $green++
ELSEIF ($choice2 = 6)
  $colour="blue"
  $blue++
ELSEIF ($choice2 = 7)
  $colour="violet"
  $violet++
ELSEIF ($choice2 = 8)
  $colour="grey"
  $grey++
ELSEIF ($choice2 = 9)
  $colour="white"
  $white++
ELSEIF ($choice2 = 10)
  $colour="silver"
  $silver++
ELSEIF ($choice2 = 11)
  $colour="gold"
  $gold++
ENDIF 
Return()

:done
Sleep(1000)
SayWait("Actually I really like $colour")
Halt()

This script he is always unsure of his answer until he chooses the same one a few of times or twice in a row.

#2  

This great Rich. I've been wanting to add this to my B9 and was thinking about how to write the script. Now, Here it is! Thanks!

#3  

Yes.....

Now i remember it....

Thanks Rich ;)

Thanks for sharing

Regards Sakis :D

United Kingdom
#4  

That code is pretty old and probably could be written a lot better now so feel free to do so :)

To be honest, it was knocked up for a single run so provided it worked that's all that mattered, it only needed to work once.

It was also written before the syntax changes to EZ-Script so there may be a few errors, nothing too difficult to fix and ARC will tell you what the errors are if you run it. Personally I'd use it as a base but rewrite it from scratch to ensure no errors and to ensure it works the way you want it to, it should be pretty easy to follow :)

#5  

ok,

I'll try to write the code and use it with speech recognition.

#6  

i write & run the code

and i saw this message

Start 2: $answer = GetRadom (1,3) > Error on line 2: Missing String Quotes or Invalid Expression: GetRadom ( Done (00:00:00.0100000)

United Kingdom
#7  

Check for typos ;)

The command is GetRandom() you're missing an n :)

#8  

When you are in a hurry blush