Asked — Edited

Yes Or No Script

I want to make my robot able to choose yes or no by itself. I made this script but theres something wrong with it because I can't save it.

$Yes=0

$No=0

$choice1 = GetRandom(0,1)
If $choice1= $Yes
   Controlcommand("script manager", scriptstart, "Yes")
Else If $choice1= $No
   Controlcommand("script manager", scriptstart, "No")
ENDIF 


ARC Pro

Upgrade to ARC Pro

Harnessing the power of ARC Pro, your robot can be more than just a simple automated machine.

United Kingdom
#1  

Yes and No both equal 0, the script will only either say Yes or end.

Also, it should be ElseIf not Else If.

Good practice is to use a 0 for off, false or no and 1 for on, true or yes.

Try;

$No=0
$Yes=1

$choice1 = GetRandom(0,1)
If $choice1= $Yes
   Controlcommand("script manager", scriptstart, "Yes")
ElseIf $choice1= $No
   Controlcommand("script manager", scriptstart, "No")
ENDIF

That said, the Yes & No variables are redundant really, I'd just do this;

$choice1 = GetRandom(0,1)
If $choice1= 1
   Controlcommand("script manager", scriptstart, "Yes")
ElseIf $choice1= 0
   Controlcommand("script manager", scriptstart, "No")
ENDIF
United Kingdom
#3  

Sorry, I didn't pick up on that error.

IF($choice=1)
ElseIf($choice=0)

is the correct syntax, you forgot the brackets.

#4  

I tried this but it just kept on going. it never stopped.

United Kingdom
#5  

What do you mean it never stopped? There is no loop in the code so it would get through the IF and would stop...

FYI, the code should be (for anyone who searches and for you if needed)


$choice1 = GetRandom(0,1)
IF($choice1=1)
   Controlcommand("script manager", scriptstart, "Yes")
ElseIf($choice1=0)
   Controlcommand("script manager", scriptstart, "No")
EndIf

While it's not required since the code doesn't go anywhere after the EndIf you could add in some Halt() commands to ensure the script ends...


$choice1 = GetRandom(0,1)
IF($choice1=1)
   Controlcommand("script manager", scriptstart, "Yes")
  Halt()
ElseIf($choice1=0)
   Controlcommand("script manager", scriptstart, "No")
  Halt()
EndIf

United Kingdom
#6  

And to make it that little bit better and add in confidence, like @MovieMaker has been wanting for a while you could do something a little bit like this, where $confidence is determined by the question asked in another script;


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

If($response <= $confidence)
  ControlCommand("script manager", scriptstart, "Yes")
Else
  ControlCommand("script manager", scriptstart, "No")
EndIf

Or if you wanted to use the routine within a script rather than to call a yes or no script;


# Some script...
#this could be read from a file or database possibly
$confidence = $activity1likelihood
Goto(decide)
If($decision = 1)
  # Carry out the task
Else
  # Refuse to carry out the task
  SayWait("No way, I dont want to do that")
EndIf
# More script

# End of main script
Halt()

# Decision routine
:decide
# Get a response value
$response = GetRandom(0,100)

# Check the response against the likelihood or confidence
If($response <= $confidence)
  $decision = 1
Else
  $decision = 0
EndIf
Return()

# Other routines

Or if you want the decision code to be a separate script you can pause the main script like;


ControlCommand("script manager", ScriptStart, "decide")
$decisionscriptrun = 1
WaitForChange($decisionscriptrun)
If($decision = 1)
  # Carry out the task
Else
  # Refuse to carry out the task
  SayWait("No way, I dont want to do that")
EndIf
# More script

And the decision script;


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

# Check the response against the likelihood or confidence
If($response <= $confidence)
  $decision = 1
Else
  $decision = 0
EndIf
$decisionscriptrun = 0

If it's not obvious the scripts above still need some work and fine tuning for whatever the task is and however the confidence and likelihood is fetched. But it's the bones to put the meat on.

I think I got a little carried away but I needed a short break:)

#7  

I have experimented with this top one but it doesn't seem to work. it always chooses no.

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

If($response <= $confidence)
  ControlCommand("script manager", scriptstart, "Yes"Winky
Else
  ControlCommand("script manager", scriptstart, "No"Winky
EndIf

What can I do to fix it?

United Kingdom
#8  

Where's it getting it's confidence from?

Provided the random number generated for the variable $response is less than it's confidence it should answer yes. Set $confidence at 100 and try it.


# Get a response value
$response = GetRandom(0,100)
$confidence = 100

If($response <= $confidence)
  ControlCommand("script manager", scriptstart, "Yes")
Else
  ControlCommand("script manager", scriptstart, "No")
EndIf

That will always answer yes.

You can also add the variable monitor control and look at what $response is when it's being picked. If it's always answering no it is always picking a number higher than $confidence

United Kingdom
#9  

The script works fine. Have a look at this project here. Set the confidence with the slider and start the Yes No Script.

Let me know how you get on. If you still have trouble let me have a look at the project as something else may be causing it to always say no.

#11  

I bookmarked this script, it can be very useful method to call. Technopro way to go!