Asked
— Edited

I am writing a script for playing a game with my robot. I am stumped on what to put in the script to keep score. How would i do that?
Thanks
I am writing a script for playing a game with my robot. I am stumped on what to put in the script to keep score. How would i do that?
Thanks
EG... your inmoov just scored a point in a game
$inmoov =$inmoov+1 or $inmoov++
... then later you scored a point
$human=$human + 1 or you can use $human++
at the end of the game just compare values
if $inmoov>$human
say(I won, nice game")
elseif $inmoov=$human
say("it's a tie, want to play again?")
else
say("You won, nice game")
endif
Something like that, anyway
Code:
I've combined my method into one script there. Usually the $P1_score = 0 (and P2, P3 etc) are defined in the init script to avoid accidental resetting.
Then the code for the game is a new script. At the end of the script has the If shown above.
Code:
Code:
This is where I still struggle with these variables - how to define them. How do I define $human / $inmoov?
I use an init script which defines all of my variables. For example you could have this in an init script which runs automatically on connection or on load.
Code:
I have many variables on my projects due to the way I write scripts in ways that can be reused and easily modified. Usually I rewrite public scripts to include the variables in the script and define them amongst the first few lines. In reality these variables on my projects are defined in the init script, this avoids accidental resetting of counters etc. should there be a problem with a script stopping.
$human="Bob" or something like that... or whatever name you wish...
Code:
Code:
Also, I noticed you are using WaitForChange for the response in your script. You should use WaitForSpeech(), it will work much better.
Here's what I have at the beginning of my script to set the variables;
Code:
it's adding up correctly but saying the wrong thing.
Code:
On this one InMoov announced he won.
Code:
You are effectively only adding a 1 to the end of the string. "Human = 0" + 1 is "Human = 01".
It is saying the correct thing for what you are asking to to say. What you are asking for is not the same as what you want.
Your variables for the scoring aren't decimal they are strings. The lines of code should be;
Code:
These are decimal and you will be able to use math with them. You cannot use math with strings.
With these lines of code $human + 1 would be 1, then 2, then 3 as the variable is a number not a string.
before your game set your variables like this... then start the game...
Code: