K-9 asks "Would you like to play a game?"
So from the famous(ish) line from the movie "War Games", I have taught K-9 a simple, but fun game to entertain people and wanted to showcase it here. I've had some time on my hands, and I gave scripting a game a go, the game being "Rock, Paper, Scissors" aka "Roshambo" aka "lots of other things". As K-9 doesn't have any hands I had to think of a way for him to play this game with people. The following video shows the solution I came up with...
So yes, using the Exec() script command to open, show, and close pictures was the way to go, and I'm fairly pleased with the result. There is a bit more I want to do with it, such as add more photos (preferably funny ones) for each each word, try to get better results from using the "Random" scripts as one of them doesn't seem to fire very much, and the main thing I want to add is a game counter. But for now, and for anyone interested, I have done a quick tutorial for how I did it which, for anyone how doesn't now how to use the Exec() commands, explains how they can be utilized.
This is a simplified version from what's in the video, with a few of the Cheat Sheet commands taken out (such as the rotating ears) which are only relevant to K-9's build and project. So on with the tutorial...
1)Find yourself some pictures, three rocks, three papers, and three scissors, and save these in your "Pictures" folder on your computer. You will need the command paths for these a bit later. They can be found by right clicking on the photo then click on "Properties". The command path you need can be seen in "Location", but you will need to add a forward slash and the name of the photo. Below is an example...
so your full command should look something like this...
C:\Users\steve_000\Pictures\rock paper scissors\rock 1.PNG
We will use these command paths shortly.
2) Add a Speech Synthesis control to an ARC project.
3) Then add a Speech Recognition control.
4) In the Speech Recognition control, you will need to add 4 new commands. Open the config menu (gear icon) on the speech rec control and type in 4 new "Phrases"...
Lets play rock paper scissors Rock Paper Scissors
5)Here is where you will need your command paths for the photos. Look for the # symbol to see where you will need to put your own command paths. In the first phrase, add the following script...
NOTE: The following scripts have been improved and updated, although the one's below still work. Check out post #11 on page 2 for the updated version.
ControlCommand("Speech Recognition", PauseOn)
sleep(1000)
sayezbwait("Okay then. That sounds like fun. You start.")
ControlCommand("Speech Recognition", PauseOff)
6)In the second phrase "Rock", add...
#rock
ControlCommand("Speech Recognition", PauseOn)
$rock = GetRandom(0,2)
if($rock = 0)
sleep(1000)
Sayezb("Rock. That is a tie. Let's try that again.")
#The exec command path below is what needs to be changed to
#with your own command path.
exec("C:\Users\steve_000\Pictures\rock paper scissors\rock 1.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
elseif($rock = 1)
sleep(1000)
Sayezb("Paper. Paper, wraps Rock. So, I win.")
#Change to your command path below
exec("C:\Users\steve_000\Pictures\rock paper scissors\paper 1.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
elseif($rock = 2)
sleep(1000)
Sayezb("Scissors. Rock, blunts Scissors. Well done. You win.")
#Change to your command path below
exec("C:\Users\steve_000\Pictures\rock paper scissors\scissors 1.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
endif
sleep(2000)
ControlCommand("Speech Recognition", PauseOff)
7)Then in "Paper"...
#paper
ControlCommand("Speech Recognition", PauseOn)
$paper = GetRandom(0,2)
if($paper = 0)
sleep(1000)
Sayezb("Rock. Paper, wraps Rock. You are good at this. Well done.")
#Change to your command path below
exec("C:\Users\steve_000\Pictures\rock paper scissors\rock 2.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
elseif($paper = 1)
sleep(1000)
Sayezb("I guessed paper too. That makes it a tie. Let's try again.")
#Change to your command path below
exec("C:\Users\steve_000\Pictures\rock paper scissors\paper 2.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
elseif($paper = 2)
sleep(1000)
Sayezb("Scissors. Scissors, cut Paper, so, I beat you that time. Unlucky.")
#Change to your command path below
exec("C:\Users\steve_000\Pictures\rock paper scissors\scissors 3.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
endif
sleep(2000)
ControlCommand("Speech Recognition", PauseOff)
8)And finally "Scissors"...
#scissors
ControlCommand("Speech Recognition", PauseOn)
$scissors = GetRandom(0,2)
if($scissors = 0)
sleep(1000)
Sayezb("Rock. Rock, blunts Scissors. I win. You are not very good at this.")
#Change to your command path below
exec("C:\Users\steve_000\Pictures\rock paper scissors\rock 3.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
elseif($scissors = 1)
sleep(1000)
Sayezb("Paper. Scissors, cut Paper. Nicely played. Let's try again.")
#Change to your command path below
exec("C:\Users\steve_000\Pictures\rock paper scissors\paper 3.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
elseif($scissors = 2)
sleep(1000)
Sayezb("Scissors. That makes it a tie breaker. Let's see if we can do better.")
#Change to your command path below
exec("C:\Users\steve_000\Pictures\rock paper scissors\scissors 3.png")
sleep(3000)
$attributes = "/F /IM dllhost.exe"
Exec( "taskkill", $attributes )
endif
sleep(2000)
ControlCommand("Speech Recognition", PauseOff)
9)Now Click "Save" to save the changes made in the speech rec control.
10)Now plug in your headset or microphone and say to your robot "Lets play rock, Paper, Scissors.", and enjoy the game.
And that's all there is to it. It's no work of art or anything, and as I mentioned before, improvements can and hopefully will be made. But it was something I wanted to try and friends and family love playing it with K-9.
If anyone wants to help a guy out and make changes to improve the scripts above, please do so. The one thing I would really like is a "first to 5 points" game counter which I tried various ways of doing so using a $counter = 0 variable and other things, but nothing worked the way I wanted it to. If anyone wants to add that to my script, I would be forever grateful.
So I hope you enjoyed the video, and for those who didn't know how to use the Exec() script command, I hope this helped. If you have any games or game ideas you would like to share then please feel free. And when I get around to making any more games, I will post them here too.
Steve.
Other robots from Synthiam community

Lumpy's Lumpy's Roomba Rover

Buratino's Buratino - Humanoid Animatronic

@WBS.
That's great. I'll check it out tomorrow. I look forward to seeing what changes you've made and compair notes. I made a few changes to my version as well this evening, adding some more GetRandom() commands to display more pictures, and give more random responses to each robot answer. I'll post it here tomorrow also with hopefully another quick video. I've still got a lot to learn in regards to writing script as I'm only used to writhing 3, 4, 5 line scripts so this was a bit of a challenge, but I think it all worked out. I haven't really tested it yet, but the short tests I did seemed okay.
A bit of an update for the "Rock, paper, Scissors" game.
I have added in a few more random script lines for the category (Rock, paper and Scissors) as for some reason the third ($rock = 2) random code wouldn't trigger, so i duplicated the first one and put it at the end. It is marked as "#Redundant but needed", and it has done the job so the three main categories all now fire as expected. As far as I'm aware I scripted it right the GetRandom() parts right, so not sure why it didn't work before. Maybe someone could confirm that what I did is correct.
I have also added random script lines for K-9's responses, so now he doesn't always say the same response for his guess. Along with this, I have also added some more fun pictures to go with his responses, along with some "You win/I win" pictures that makes the game a little more interesting and engaging to play.
Here's an updated video demonstration with the changes made which I hope you will enjoy...
I have also posted the updated scripts below. Remember, the same thing still applies where if you wanted to use the scripts yourself, you will need to change the exec("C:\Users\steve_000\Pictures\rock paper scissors****** *.png") command paths to use your own photos.
GAME START
ROCK
PAPER
SCISSORS
With the new script changes, the game works SOOOO much better than it did before as ($rock = 2) "Scissors" triggers much more often now. Again, this ain't no masterpiece, but it was my first attempt at writing something a little more complex than I'm used to, using multiple variables and random codes in one (or three) places. There is probable a much better and cleaner way to write this little game, but it works and I'm happy with the results. I hope you are too.
BTW, the spelling mistake for "Wrap's" was deliberate for speech synthesis reasons, as it didn't seem to pronounce it right, and "Rap's" works much better.
@WBS.
I used some of your picture suggestion in the update, and they look good. I'm about to try your version. Looking forward to seeing how you went about scripting it, and to playing it.
Steve.
@WBS.
I just checked out your version of RBS. What on earth have you done to my game?
Kidding of course. It's great what you have done with it, and I absolutely LOVE the points counter. It works really well (I didn't expect anything less). It was a joy to play and interest to see who you rewrote it. It much smaller and cleaner, and I can see by what you have done that I have a long way to go in improving my knowledge of writing scripts. Info see your point in putting the main body of the game in the speech recognition control. I may actually change mine to Cheat Sheet commands and move the game to a script manager.
I think I see way my attempt at including a counter failed as I was trying to take points from three separate scripts, where as the main body of your version is in one script. Although I guess it could be done with a counter script outside of the speech rec control which I would love to include in my updated version, but that's a bit beyond my ability just now.
If I could nit pick on one thing though, the pictures wouldn't activate and I got an error on line 82 (or near that). It was he EXEC() variable that was causing the trouble. I don't know why that was as it looked good to me.
Anyway, I really liked what you did with it, and thanks for sharing the download link.
Steve.
Hi Steve; Glad you liked it. I'll look into why the picture thing is failing. Working on the random K9 responses now. I plan to have the response sentences broken into 3 parts, each of which will be randomly changeable to make a complete, coherent sentence. That should mix up the responses quite a bit. I'll be incorporating your new phrases as well, if that's ok. For instance a randomly chosen phrase like "I chose " or "I selected " would be combined with whatever K9 chose (rock, paper or scissors). Then appending on a random suffix phrase to complete the sentence. It will also have the random parts chosen on the basis of whether K9 won or lost a given round. Such as, if he won, the sentence might be: "Lucky me, I chose rock. Doing a happy dance in my mind!"
The parts being: "Lucky me," "I chose" "rock" "Doing a happy dance in my mind!"
If K9 loses: "Maybe next time. This time I selected paper. How can you be so lucky?".
Those parts being: "Maybe next time. This time " "I selected" "paper." "How can you be so lucky?"
Sounds complicated, but it's really not. I'll write over my old project with the new stuff on the cloud when I finish. And feel free to use whatever I have written in your version. The whole thing if you want. It's really still your creation. I'm just doing some grunt work on it. It's fun for me.
@WBS.
No problem. Incorporate away.
If I get timeater today, I'll try to incorporate the point counter in to my version after I've moved a few things around. I'm still trying to think of another simple game I can try to add that's within my ability to write. I have a quiz idea, so maybe I'll give that a try.
Hi Steve; Hope you are doing well and having fun. I know I am. Nearly finished the changes I wanted to make. Even found a Script bug. Just wanted to share something about the random function. It occurred to me that if it was missing the last possibility (2), then the thing to do was eliminate that as being the last one. I did this simply by going one higher in the random function, from 2 to 3. Now it chooses a number from 0 to 3 instead. I used a following statement to make anything above 1=2. Like this:
This way the number 2 is no longer the last possible choice, 3 is. So 2 comes up as often as anything else. And if 3 happens to come up (which it rarely does, just like 2 rarely came up) then it is simply converted to 2. Seems to work well. I did the same thing in choosing a phrase from the GetRandom function.
Unfortunately the bug I found affects my method of choosing a random picture to show during a given round, but I have a work around for that for now. Not elegant, but work arounds rarely are.
@WBS.
Hi. Yeah I'm good thanks. Hope you are too. The addition of adding another random possibility was similar to what I did and it works great now so all is good there now. Interesting find about the script bug you discovered (I just read your other thead asking about this), and glad you found a workaround. I might have a go at a multiple choice quiz this week using similar methods, so I'll keep you posted with how I get on with it.
I have a new update for a quiz game idea I've been working on. Just finishing off the final touches.