Every Tuesday, Mike Sylvester brings you REVOLUTIONARY, a look at the wide world of Wii possibilities.
In the coming weeks, I'll be detailing the process of writing a GlovePIE script, from concept, through testing, to completion. You will see that it's not so tough to get something running, and I hope you'll also get a better understanding of the mechanics of the hardware inside the Wii Remote and its accessories.
This time around, I'll be deconstructing the simplest of the GlovePIE scripts I've written to date, but also one of the most rewarding -- Alien Hominid.
The story of the Alien Hominid franchise's development is inspirational. A team of indie developers releases a free game to the PC gaming masses, then forms an indie company with a few other ambitious individuals, and they turn the IP into a commercial console success. The original game prototype is still freely available to play, but next to its console successors, its flaws become glaringly obvious. Being only one level long, one would think the length of the game is the biggest problem, but to complete that level you must suffer the controls. The keyboard is less than ideal for the twitch movements this game requires, and it's made even more nightmarish by forcing us to use the right-hand oriented arrow keys for movement and left-hand oriented keys for actions. It's grandma's recipe for carpal tunnel syndrome.
What does not kill us leaves us crippled
This is where the Wiimote flies in to save your weary digits and the day. GlovePIE makes it a sinch to orient simple keyboard controls in a way that's familiar and comfortable, and makes this PC game feel more akin to its console brethren.

Doesn't that look better? There's a number of ways to get the keyboard configuration to translate to those buttons in GlovePIE, but the code below is tested and proven to work. Not every game will respond to your commands or statements the way you expect, so you may have to try a few different methods of doing what logically amounts to the same thing. Something to look for in scripts and other program code is developer comments. Comments are notes inserted by the script writer or programmer to explain how something works, or how it will affect the running of the program if changed. In GlovePIE // signifies the beginning of a comment on a line of code. When GlovePIE is running the code, it will not attempt to run anything written after the doubled forward-slashes on a line. You can also comment multiple lines by placing /* where you want to start your comment, and */ where you want to end it.
Keyboard.A = Wiimote.One //Wiimote button 1 acts like keyboard key A -- shoot
Keyboard.S = Wiimote.Two //Wiimote button 2 acts like keyboard key S -- jump

GlovePIE automatically colors code it recognizes
Now we're going to set the Wiimote's D-pad to emulate the keyboard's arrow keys. We could do it the same way as above, where a Wiimote input is set to equal a keyboard input, but after testing, I found using that for the directional controls made the game play slightly sluggishly. Like I said, you never know exactly how a game or program is going to respond to your code until you test things out.
If Wiimote.Right //checking to see if the Right direction on the D-pad is "true" (tapped or pressed)
Up = True //keyboard key Up is held in this condition
Else //if the condition is not met, the following is performed
Up = False //keyboard key Up is not held
EndIf //ends this statement
The Remote's primary orientation is vertical like a TV remote control, and GlovePIE has the D-pad's directions mapped accordingly. The program doesn't change the labeling when you turn the controller sideways, so we compensate in our code. Right is up, left is down, up is left, and right is down.
If Wiimote.Left
Down = True
Else
Down = False
EndIf
If Wiimote.Up
Left = True
Else
Left = False
EndIf
If Wiimote.Down
Right = True
Else
Right = False
EndIf
And that right there is a complete script. You can copy and paste those lines of code into GlovePIE, run it, and play through the game as I have. It's important to understand that every game played with the Wiimote must have waggle, or rumble, or fancy LED shows, but you're free to add in any of that if you like. It's your game now, so do whatever you can to enrich it.
I made the above video immediately after pairing my Remote with my computer. Since, I hadn't run the script prior to filming and I didn't include any code to turn off or otherwise stop the LEDs from their "discoverable mode" flashing, they flashed throughout the video like a beacon drawing forth skeptics to yell "FAKE!" I've noticed that any normal LED activity (1 LED on, no LEDs on, or LEDs steadily flashing) is something that will often be cited by the "fake callers" as evidence to their cause. Right now, we're going to guard against that by putting in some code to make the LEDs do something they wouldn't under normal operation. You see, we have complete control over the LEDs, so whether they're on, off, flashing, or "KITT scrolling" is up to us.
If 0 = 0 //trick GlovePIE into starting a loop, like saying "if the sun is hot, do this"
If var.KITT = 0 //checking to see if the value of this variable is equal to 0
Wiimote.Leds = 1 //lighting LED1
EndIf //end the nested statement
If var.KITT = 1 //checking to see if the value of this variable is equal to 1
Wiimote.Leds = 3 //lighting LED1 and LED2
EndIf //end the nested statement
If var.KITT = 2 //checking to see if the value of this variable is equal to 2
Wiimote.Leds = 6 //lighting LED2 and LED3
EndIf //end the nested statement
If var.KITT = 3 //checking to see if the value of this variable is equal to 3
Wiimote.Leds = 12 //lighting LED3 and LED4
EndIf //end the nested statement
If var.KITT = 4 //checking to see if the value of this variable is equal to 4
Wiimote.Leds = 8 //lighting LED4
EndIf //end the nested statement
If var.KITT = 5 //checking to see if the value of this variable is equal to 5
Wiimote.Leds = 12 //lighting LED3 and LED4
EndIf //end the nested statement
If var.KITT = 6 //checking to see if the value of this variable is equal to 6
Wiimote.Leds = 6 //lighting LED2 and LED4
EndIf //end the nested statement
If var.KITT = 7 //checking to see if the value of this variable is equal to 7
Wiimote.Leds = 3 //lighting LED1 and LED2
EndIf //end the nested statement
Wait 100ms //wait 0.1 seconds before processing the next line
var.KITT = (var.KITT + 1) % 8 //incrementing (by 1) the value of this variable that is checked throughout the statement; restarts from 0 when it reaches 8
EndIf //end the statement
Perhaps the #1 reason why I'm so enamored with writing my own scripts for game controls is that I can enhance the games with features that may not have been included by the developers. This script above is complete, and the game will play (more or less) as the developers intended with it as is, but why stop here when we can add auto-fire?
If pressed(Wiimote.A) //checking to see if the A button is pressed and released
toggle(var.AF) //flip this variable between "True" or "False" if the above condition is met
EndIf //end the statementIf Wiimote.One //checking to see if the 1 button is "true" (tapped or pressed)
If var.AF //checking the "on" or "off" status of this variable we affected in the previous statement
Key.A = True //keyboard key A is held
Wait 100ms //waiting 0.1 seconds before processing the next line
Key.A = False //keyboard key A is released
Wait 100ms //waiting 0.1 seconds before processing the next line
EndIf //end the nested statement
EndIf //end the statement
And there you have it. Although Alien Hominid remains brutally difficult, you can now lay down a steady spray of weapon fire without taking your finger off the 1 button. This was a case of a game desperately needing a new control scheme just to become playable, but we can write scripts for any reason. Maybe you want to make a game more challenging to play, or feel more authentic. We'll cover more possibilities next week in Revolutionary.
Updated: Thanks to James for the correction














Reader Comments (Page 1 of 1)
6-26-2007 @ 2:24PM
Rocket Man said...
If you could get Rocket Jockey to work with a Wiimote, and we're talking steering by turning the wiimote, I'd be ever so grateful.
Reply
6-26-2007 @ 2:49PM
Mike Sylvester said...
@Rocket Man
Hmm... I never could get that game to run on my computer when it came out. If I have any luck running it now *fingers crossed*, I'll consider it. I really love retrofitting old games with Wiimote controls.
Reply
6-26-2007 @ 10:13PM
Billy_McBong said...
awesome
i need to buy a blue tooth adapter so i can start using my Wiimote on my computer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free gaming stuff(including Wii points and controllers):http://gaminglagooon.info/
Reply
6-27-2007 @ 2:55PM
zelder_man said...
Can't wait to learn to write GlovePIE script. I wanna try to write this for a game my classmates and I are making. Keep up the good work.
Reply
6-27-2007 @ 2:57PM
James said...
"var.KITT = (var.KITT + 1) % 8 //incrementing the value of this variable that is checked throughout the statement by 8%"
OK, I don't think the OP wrote this code, but "incrementing... by 8%" is just too hilarious to let slide. % is the modulus operator; it gives the remainder of the left operand when divided by the right operand. In this case, it makes sure that 7 + 1 = 0 (not 8).
Anyway, yeah, GlovePIE is pretty cool, but as soon as I bought my Bluetooth adapter I realized I never play any (and I do mean *any*) PC games anymore, except the occasional bout of Command and Conquer with my wife, which the Wiimote is no good for (I rely very heavily on keyboard shortcuts, of which there are dozens). I wish I had something to use my Wiimote with on my PC...
Reply
6-27-2007 @ 3:01PM
Mike Sylvester said...
@James
I knew it didn't seem right when I wrote that comment at 2a.m. With a 100 millisecond delay, an 8% increment would only update the LEDs every 1.25 seconds, and it's obviously moving faster than that! I'll edit the post with the info you've provided. Thanks.
Reply
6-29-2007 @ 4:13AM
Tim said...
I'm in the same boat as you James, I got my Wiimote paired up with my PC months ago, but I have hardly any games worthy to play it with. It would be nice to hear more good uses for it rather than GlovePIE talk that I don't need.
It has been good to use it as a nice wireless controller though. I've used it to play a bunch of indie PC games, such as Within a Deep Forest (http://nifflas.ni2.se/index.php?main=03Within_a_Deep_Forest).
Also, I'm sick and tired of seeing that KITT loop in every second example script. It wouldn't hurt to get some basic programming practice, because I can see a dozen other better ways to write that code.
Reply