Part One: Racing the Sun

The real power of the Myo armband comes into play when you start combining poses with data from the IMU like pitch, yaw, and acceleration. This gives you a near unlimited number of gestures to play with.

I’m Paul (@PBernhardt), and welcome to the first part of our second series of tutorials on Myo Script (Start here if you missed it). We’re going to Myo-enable Race The Sun, by Flippfly. The game is available on Steam and the Humble store, but there is also a free demo on Kongregate. It’s a simple game where you control a solar powered plane forever flying towards the sun. You can move left or right to avoid obstacles, and if you crash or the sun goes down (because you were in shadows too long, or slowed against the edge of a wall) it’s game over. This is a great game that’s lots of fun to play with a Myo armband. Or at least, it will be once we write this script to control it.

Race The Sun

It’s important to keep in mind that Flippfly had nothing to do with this (other than making a great game!). They didn’t need the SDK or a Myo themselves, we are building the script completely without their input. You can apply the same techniques to Myo-enable any appropriate app.

If you ever get stuck (or just want to play right away) the completed script is in the Myo Market. Now, let’s get started.

Starting Out

My previous tutorial covered the basics, so I won’t be explaining anything covered in there. Let’s start out with a simple skeleton script. Create a new Myo Script with a new scriptIdscriptTitle of “Race The Sun”, blank scriptDetailsUrl and implementations of onForegroundWindowChange and onPoseEdge that just print to the debug console. Implement activeAppName to return scriptTitle. Feel free to use the work you did for the last tutorial as a reference.

You should come up with something like this:


scriptId = 'com.thalmic.examples.racethesun'  
    scriptTitle = "Race The Sun"  
    scriptDetailsUrl = ""

    function onForegroundWindowChange(app, title)  
        myo.debug("onForegroundWindowChange: " .. app .. ", " .. title)


    function onPoseEdge(pose, edge)  
        myo.debug("onPoseEdge: " .. pose .. ", " .. edge)

    function activeAppName()  
        return scriptTitle

Now, load up the script and go to Race The Sun on Kongregate (or launch the actual game if you have it), and note what you get in the onForegroundWindowChange debug output.

For the actual game it’s just “RaceTheSun” (without spaces). At Kongregate, the title will contain “Race The Sun” (with spaces), but probably have some other bits referring to the browser you used to get there. There are a few different ways to search for patterns inside of strings in Lua. Try to modify onForegroundWindowChange to only return true when the title contains “Race The Sun” or “RaceTheSun”. If either of those strings are detected, you’ll also want to set the lock policy to none (since we’re playing a game and the Myo armband is always active.)

I’ll give you the answer tomorrow, when we’ll also talk about how to control the glider in an action game like this. In the mean time, if you get stuck shoot me a tweet or ask for help on our forums.

Good luck!


Enter your email address and get all latest content delivered to your inbox every now and then.