Using Exec() Commands To Help Make A Game

Steve G

United Kingdom
robot video thumbnail
robot video thumbnail

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

By — Last update

ARC Pro

Upgrade to ARC Pro

Become a Synthiam ARC Pro subscriber to unleash the power of easy and powerful robot programming

#25  

Is this video playing on the PC or the tablet on the K-9?

United Kingdom
#26  

On the tablet (or PC as they are both Windows 8.1).

#27  

Ok, I don't know about Adobe but you can use the Exec function again like this:


$WebSite ="https://www.youtube.com/v/?v=VrKdLSiUvaM&autoplay=1 "
Exec($WebSite)

The things to notice are: The substitution of the "watch" portion of the Youtube link with v/. As in: $WebSite ="https://www.youtube.com/watch?v=VrKdLSiUvaM&autoplay=1" Exec($WebSite) $WebSite ="https://www.youtube.com/v/?v=VrKdLSiUvaM&autoplay=1" Exec($WebSite)

That starts it in full screen. The "&autoplay=1" added at the end gets it playing upon loading.

Hope that helps.

EDIT: Oddly, if you click the link in this post it does not come up playing. However, running it in a script it does.

EDIT AGAIN: There seems to be an oddity in the character combination of 1" in my post. Somehow it comes up as 1"; in the post. This, in turn, makes the link not work quite right. If I add a space to separate the 1 from the " things work properly and, in this case, the video starts up upon loading as it should. Just a little quirk in the system. Much like me, come to think of it. :D

United Kingdom
#28  

@WBS.

Okay cool. I,ll give that a try shortly.

Thanks.

United Kingdom
#29  

@WBS.

I tried the...

$WebSite ="https://www.youtube.com/watch?v=VrKdLSiUvaM&autoplay=1 " Exec($WebSite)

and it worked straight off which was great which was cool, so thank you for that (funny why just clicking the link doesn't work). Couldn't get the..

$WebSite ="https://www.youtube.com/v/?v=VrKdLSiUvaM&autoplay=1 " Exec($WebSite)

to work though. Anyway here is an example of a website that has an embedded weather video that uses Adobe Flash Player to play it...

BBC Weather for London

If I could get this sort of thing to work, that would be great if anyone else has any ideas.:)

#30  

I'll take another stab at it. This assumes you have the entire internet path to the flash video you want to play. eg: http://Mysite.com/MyFlashVideo.swf.
Because the settings needed have quote marks in them, they can't be copied into variables in the scripts so I opted for a generic file to reside on the hard disk somewhere. The code for it is:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Flash Video</title>
</head>

<body style="margin:0">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%">
  <param name="movie" value="http://Yoursite.com/MyFlashVideo.swf" />
  <param name="quality" value="high" />
  <param name="wmode" value="transparent">
  <PARAM NAME="SCALE" VALUE="exactfit">
     <embed src="http://Yoursite.com/MyFlashVideo.swf"
      quality="high"
      type="application/x-shockwave-flash"
      WMODE="transparent"
      width="100%"
      height="100%"
     SCALE="exactfit" 
      pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>

Just copy and paste the above into a notepad and save it under the name of your choice with the "html" extension.

Note that you have to enter the http path and swf name twice. Once for the "Movie" param name and once for the "embed src" tag.

Then, in the script, use the Exec command to run it when desired as in:


Exec("C:\RunTheFlash.html")

Don't know it that's quite what you want but maybe it will lead you to it.

United Kingdom
#31  

@WBS.

Thanks for the info you posted above. Unfortunately it didn't work for me. I put un the URL I was testing with but a blank page came up. Below is a screen grab of the web page containing the relevant info...

User-inserted image

www.bbc.co.uk/weather/2643743

I tried different variations and managed at one point to open the site, but wouldn't play the video. I guess I'm not to fussed with this at the moment so may put it on the back burner for now. but if you, or anyone else reading for that matter, would like to play around with it further if you have time, I would be grateful.

Steve.

#32  

Yeah, that's the problem. To make my method work you have to know the exact path to the flash file you want to play, as well as, the name of the file. Looking at the source code for the web page you specified I believe I found the name and path for the file in question, Problem is, like many web sites, it is obfuscated so that people can't just play it alone. They want you to have to open the web page (and see the ads) to be able to play it. For this they also have their own system of playing the Flash files to further hide it.

I tried just adding the extension "swf" to see if it would play, but it wouldn't which confirmed my suspicions. Thing is, even if I could get it to play, the name will change every time they update the file so you would have to find the new name and enter it in the html file every time. That could probably be automated, but would not be worth it if you can't even play the file anyway. I'll look about and see if anyone has an answer to all this and let you know.