Using Exec() Commands To Help Make A Game

 
#1

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...

User-inserted image

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 EZ-Builder 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.

Code:

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...

Code:

#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"...

Code:

#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"...

Code:

#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 Winky.

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. Smile

#2

I did have another video to share with you guys, but YouTube is having problems uploading it. I'll try again tomorrow. And below is a link for the project for anyone who what's to at with it..,

RockPaperScissorsgame.EZB

#3

lol, sweet idea Steve. I like the pictures coming up to go along with it, great concept!

#4

@Jeremie.

He he, thanks buddy. I started with just one picture for each subject but then thought "Blah, boring", so went with some more amusing ones (some not seen in video). I say, it's only a simple game, but this kept my nephew and niece (and adults) entertained for a good couple of hours (or at least until the battery went flat) when they came around the other day.

Trying to think of other games I could do with my still limited, but slowly growing scripting knowledge. *confused* Smile

#5

Haha! What fun. Brilliant. Your having way too much fun with that little dog of yours. The Dr's going to want him back if you keep teaching him these tricks. Tongue

#6

Lol, thanks Dave. Funny, talking about the Dr, I had a thought of doing a multiple choice Doctor Who quiz using similar methods with the pictures. Maybe I'll give it a go. Anyway I'm glad you enjoyed it. Thanks again. Smile

#7

This sounded like a fun thing so I played around with it for a while and made a project with what I did. I added a scorekeeper and had it announce the score every round and whose favor it is, as well as, an announcement of a winner (whoever wins 5 rounds first). I'm not sure how you wanted to display the score so I didn't put in any display of that. At the moment everything is by voice. It also asks if you want to play another game at the end. The pictures still show up as before. I'll put up the project to the cloud sometime today for you to download. I just want to clean up a few things and do a writeup on how I did it to help you understand what was done and why.

I would like to add a way to vary the responses given by K9 as it goes through the rounds, but that will take a bit longer.

Speaking of the pictures, here are some suggestions that came to mind:

Rock pictures
Picture of Rock Hudson or Kid Rock or Dwayne Johnson
A rock bouncing off a cartoon character's head or the K9's head depending on who lost

Paper pictures
Picture of a tax form or homework with an "F" on it
Newspaper with funny headline
Toilet paper
Paper airplane
Shredded paper

Scissors pictures
Wrestlers with one in a scissors hold
Kid running with scissors

Then there would be pictures of people winning and losing contests.

Also no need to limit yourself to static images. Use some GIFs. There are tons of funny ones around. Maybe with a little sound effects.

#8

@WBS.

They are some great ideas about the pictures, and especially the GIF idea, and I'm well pleased you added a score counter too. Yeah I should have said, I did actually want verbal score counter, so your project sounds great. When you load it to the Cloud, I'll be sure check it out. It will be interesting to look at the script to see where I went wrong with my "Counter" attempts.

About chairing the responses, I had a little trouble with that as mentioned in post #1. In each subject, the last response variable would hardly ever fire, so Ithought instead of having three random responses, I would duplicate the existing ones and have three of each (nine random in total).L, which would hopefully swimg the last "Scissors" response in to action more. I'll try it later and see how it goes. It'll be interesting to see your solution to this as well

Steve. Smile

#9

Okay, I've finally uploaded the game. It's called "RPS Game." It seems to have a problem pronouncing the numbers 2 and 4. I'll have to work on that. Also, I forgot to take the # symbol from in front of the Exec() commands in the RPS Main script (two places near the end). And, I had changed the SayEZB() commands to simply Say() Commands for my convenience. I will correct both these things and re-upload it soon.

EDIT
I re-uplpaded it and changed it's name so as to make it more specific. It is now called RPS Game_K9.

#10

@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. Smile