How To: Write GlovePIE Scripts

From WiiLi

Jump to: navigation, search

Contents

[edit] Interface

GlovePIE is a Programmable Input Emulator by Carl Kenner, which translates signals from the Wiimote to actions on the screen. The language used to program these actions is a scripting system that combines aspects of BASIC and C into its syntax. [More basics, like how variables are asigned, debug, etc] Image:Glovepie_stop.jpg

GlovePIE 0.28 while stopped.

Image:Glovepie_run.jpg

GlovePIE 0.28 while running - Note where the Debug Window is.

[edit] Presets

[edit] Wiimote

When you would like to take the input from one of the Wiimote's various sensors you can do so by using the variable 'Wiimote' then append a '.' then the input. For instance to get the input from the A button on the wiimote you would use:

Wiimote.A

GlovePIE can support up to 8 Wiimotes. To distinguish between each Wiimote, add the number which you want to edit. For instance, the first Wiimote would be Wiimote1 the second would be Wiimote2 so on and so forth.

[edit] Wiimote

The following is the current list of inputs that you can pull from the Wii.

  • Up - D-Pad 'Up', returns TRUE if pressed, FALSE when released.
  • Down - D-Pad 'Down', returns TRUE if pressed, FALSE when released.
  • Left - D-Pad 'Left', returns TRUE if pressed, FALSE when released.
  • Right - D-Pad 'Right', returns TRUE if pressed, FALSE when released.
  • A - 'A' button value, returns TRUE if pressed, FALSE when released.
  • B - 'B' button value, returns TRUE if pressed, FALSE when released.
  • Minus - 'Minus' (-) button value, returns TRUE if pressed, FALSE when released.
  • Home - 'Home' button value, returns TRUE if pressed, FALSE when released.
  • Plus - 'Plus' (+) button value, returns TRUE if pressed, FALSE when released.
  • One - One (1) button value, returns TRUE if pressed, FALSE when released.
  • Two - Two (2) button value, returns TRUE if pressed, FALSE when released.
  • Count - Returns the count of Wiimotes reconized by GlovePIE
  • Exists - Checks if specified Wiimote exists.
  • HasClassic - Checks if Classic Controller is attached. Returns TRUE if attached, FALSE when not attached.
  • HasNunchuk - Checks if Nunchuk is attached. Returns TRUE if attached, FALSE when not attached.
  • Battery - Battery level. If full returns 192 ( HEX 0xC0 )
  • Led1 - 4 - Led values. From 1 to 4, left to right respectivly on the Wiimote. To turn on an LED set the LED and number you want to TRUE. Ex.
    Wiimote.Led2 = TRUE

[edit] Nunchuk

When you would like to take the input from a Nunchuk plugged into one of the Wiimote's expansion bay, you can do so by using the variable 'Wiimote' then append a '.' then the variable 'Nunchuk' appended by another '.' then the input. For instance to get the input from the C button on the Nunchuk you would use:

Wiimote.Nunchuk.CButton

The following is a list of inputs you can pull from the Nunchuk. These are after you have 'Wiimote.Nunchuk.'.

  • CButton - 'C' button value, returns TRUE if pressed, FALSE when released.
  • cxx - czz - These are the forces exerted on the Nunchuk with Gravity. These values are discouraged from being used.
  • gx
  • gy
  • gz
  • JoyX - Analog Stick X coordinate value, return range is -0.99 to 0.99.
  • JoyY - Analog Stick Y coordinate value, return range is -0.99 to 0.99.
  • Pitch
  • Roll
  • ZButton - 'Z' button value, returns TRUE if pressed, FALSE when released.

[edit] Classic

When you would like to take the input from one of the Classic controller when plugged into the Wiimote's expansion bay, you can do so by using the variable 'Wiimote' then append a '.' then the variable 'Classic' appended by another '.' then the input. For instance to get the input from the A button on the Classic controller you would use:

Wiimote.Classic.A

The following is a list of inputs you can pull from the Classic Controller. These are after you have 'Wiimote.Classic.'.

  • a - 'A' button value, returns TRUE if pressed, FALSE when released.
  • b - 'B' button value, returns TRUE if pressed, FALSE when released.
  • Down - D-Pad 'Down', returns TRUE if pressed, FALSE when released.
  • Home - 'Home' button value, returns TRUE if pressed, FALSE when released.
  • L - Left shoulder button value, returns range is 0.01 to 0.99.
  • Left - D-Pad 'Left', returns TRUE if pressed, FALSE when released.
  • Minus - Minus (-) button value, returns TRUE if pressed, FALSE when released.
  • Plus - Plus (+) button value, returns TRUE if pressed, FALSE when released.
  • R - Right shoulder button value, returns range is 0.01 to 0.99.
  • RawJoy1X - Left Joy Stick X coordinate value, return range is -0.99 to 0.99.
  • RawJoy1Y - Left Joy Stick Y coordinate value, return range is -0.99 to 0.99.
  • RawJoy2X - Right Joy Stick X coordinate value, return range is -0.99 to 0.99.
  • RawJoy2Y - Right Joy Stick Y coordinate value, return range is -0.99 to 0.99.
  • Right - D-Pad 'Right', returns TRUE if pressed, FALSE when released.
  • Up - D-Pad 'Up', returns TRUE if pressed, FALSE when released.
  • x - 'X' button value, returns TRUE if pressed, FALSE when released.
  • y - 'Y' button value, returns TRUE if pressed, FALSE when released.
  • ZL - Left Z Trigger button value, returns TRUE if pressed, FALSE when released.
  • ZR - Right Z Trigger button value, returns TRUE if pressed, FALSE when released.

[edit] Keyboard

Keyboard presets is a list of keys that you can "map" the Wiimote to. To save you, and myself, from a very very long list. I will instead give you a few special keys, and how to set "map" buttons from the Wiimote to your keyboard. To set the input of a key, you can do so by using the variable 'key' followed by a '.' then the key you wish to set. So to set the "A" key to be pressed, you would do the following:

key.A = true

Now when you run the program, the "A" will will be pressed, and held, since it will always be true. To release a key, you would do the following:

key.A = false

Now the A key is no longer pressed.

So to have the "A" key just pressed, you could use the following:

key.A = true
key.A = false

The key will be pressed, then released.

If you wanted the "A" key to be pressed whenever the Wiimote's One (1) button was pressed you could do the following:

key.A = Wiimote.One

Now whenever you press the One (1) button on the Wiimote, "A" will also be pressed.

If you wat more than one button to be pressed at a time, then this command can be used:

  if
  wiimote1.a = true
  key.a = true
  key.shift = true
  endif

This would cause a capital a (A) to be typed if in a textbox.

[edit] Mouse

[ADD Mouse presets]

[edit] Commands

Aside from the Presets above, there is a variety of Commands that can be used within GlovePIE to further enhance the program.

  • // and /* */ - Two backslashes, or backslash asterisks denote Comments. Comments are used frequently by programmers to keep track of what they are doing in their code. When you run a program with Comments in it, the program skips over those lines, so technically they don't exist in the programs mind. For instance:
// This is a comment.
// if I do this:
var.me = "Wii"
// then do this:
// var.me = "Mii"
// the program will set
// var.me to "Wii" since the other line is commented out!
// Do note that each line has it's own set of '//' if you wanted to type a lot
// you could use:

/*

Everything in this block will be skipped over. It is known as a comment block.
Do note how it is started with a /* and ended with:

*/
  • wait - Pauses the program for x amount of time. Time can be measured in milliseconds (ms) or seconds (s).
  • var - Var is used to make new variables aside from the preset ones above. They are assigned by using "var.variablename". So if you wanted to make a variable called Foo, and set it to "bar", you would do the following: var.foo = "bar"

[edit] Control Structures

[edit] IF/ELSE

if, else, and elseif are a few very special commands. IF checks if the statement is true. It evaluates everything inside of it's ( ) using boolean operators. Boolean operators are:

EQUALS  ==
NOT EQUALS  !=
GREATER THAN  >
LESS THAN  <
GREATER THAN EQUAL TO  >=
LESS THAN EQUAL TO  <=

So if you wanted to check so see if var.foo was equal to "bar" you would use something like this:

if( var.foo == "bar" )
   //do something here.
endif

Notice how at the end of our statement we added endif that tells the statement when to stop executing the commands inside it. It ends the if statement.

If you wanted to check when something was true, and if it wasn't true then do something else, you could use an else statement:

if( var.foo == "bar" ) then
   //do something here.
else
   // variable foo is not equal to bar.
   // So instead of checking if( var.foo == "bar" ) then checking if( var.foo != "bar" )
   // You can just simply say "else" which means everything other then the above statement.
   // ELSE must be attached to an if statement otherwise your program will have an error.
   // ELSE is optional, but can be vital to keep the next section completely independent.
   // It ensures any variables used remain the same - even when they might be changed inside
   // the previous IF THEN section.
endif

The last statement is the elseif. If you wanted to check for multiple things all within one if statement you could do so with elseif:

if( var.foo == "bar" ) then
   //do something here.
elseif( var.foo == "foobar" ) then
   //do something other when foo is "foobar"
elseif( var.bar == "foo" and var.foo = "foo" ) then
   // Now I just used "and" to compare two things.
   // Read below for more information on that!
endif

If you need more then one thing to be true to execute a part of the script ( For instance, if two buttons are pressed, or if two variables are greater then x ) you can use boolean comparisons.

AND - only returns TRUE when statement to the left and right are true.
OR - returns TRUE when either left or right of the statement is true.

Here is an example. We'll assume that var.foo = 1 and var.bar = 5 :

if( var.foo >= 1 AND var.bar < 7 ) then
   var.x = true
else
   var.x = false
endif

In that statement var.x will be set to true since var.foo is equal to 1 and var.bar is less then 7.

if( var.foo > 0 OR var.bar < 1 ) then
   var.x = true
else
   var.x = false
endif

Again in that statement var.x will be set to true since var.foo is greater then 0. Even though var.bar is not less then 1. One part of the statement is true, that is all that is needed with an OR statement.

if( var.foo != 1 AND var.bar == 5 ) then
   var.x = true
else
   var.x = false
endif

Lastly, in the above statement, var.x will be set to false. Since var.foo is equal to 1 it fails, even though var.bar is equal to five. Both statements have to true in order for the whole statement to be true.

[edit] See Also

For a list of example scripts using GlovePIE see:

If you and the code are one:

[edit] External links

Personal tools
Online Casino - best online casino reviews.
Facebook Developers - facebook applications, facebook developers, facebook development, social network application development and viral widget social media strategy