promo
GlovePie Tutorial

WiiJ GlovePie Tutorial 1

- written by Altris 

So the first thing I think that is important to talk about in GlovePIE (as long as you know how to load a script and run it, which if you don't know how, I'll make a Part 0.5 which talks about the more basic parts of GlovePIE) is understanding that GlovePIE is based on C++ or Java programming language as far as I can tell (and if I'm wrong please inform me :). But that's not all, there is a special twist to it as any script you create runs in a constant loop. So if you get these things, you can probably skip down to the end where I give the ever wonderful first program of "Hello World!".

So first, GlovePIE seems to be based off of C++ or Java which are object oriented programing languages. Is that really important? Not that much for you to know about unless you already know about these languages. I took a couple quarters of Computer Science in college so I have some experience in C++, thus when I started with GlovePIE it's structure and syntax made complete sense to me. So if you have no experience with programming, just think of the things in the program (for example a = Wiimote1.A) as objects. Wiimote1.A is an object that you are setting equal to the letter a that you would press on your keyboard. It's about as simple as that. There is also another name for these objects (and if you do know how to program, please don't crucify me to badly for not calling things by their exact proper name :) which is a variable. In my own script I have two kinds of variables, ones that are on the wiimote (like Wiimote1.A which is the A button on Wiimote 1) and ones that I just use in the program and can be created by typing, for example, a = var.C which makes a variable C which is equal to the letter a. You'll see which this is important later on, as it allows you to do some background processing of information without doing anything to the Wiimote. So if I haven't lost everyone by now, there are two kinds of objects, or variables, in GlovePIE. The ones which are on the Wiimote (a = Wiimote1.A, and the ones which you can create in the program (a = var.Hi).

The second important thing is that the program loops continually. Now this one I would love for people to correct me if I am wrong, but I think this is called recursion. Basically when the program gets to the end, it starts running through the program again. This is much different then what you would see in a normal computer program, as you usually have to use loops to make the same section of code run again. However in GlovePIE you never need to use a loop, because GlovePIE is constantly looping through your script. So if you want to use a loop, don't. As the documentation for GlovePIE says, you probably need to think differently if you want to use a loop, but it's not necessary. But don't worry if this doesn't make to much sense, as examples are given, you'll see how the looping works.

However, one quick example for today, if you have used the flickstart script, you will notice that as you run the script, you can flickstart at any point if you want to. Now in a non-recursive program, you would have to code the script such that every time you press a button a certain part of the program would activate and loop until you told it to stop. But in GlovePIE all you have to do is say when a certain thing happens (like flicking the Wiimote) then you do something else (like output the command to start the track, in this case a key like the letter z) as GlovePIE is running constantly, just waiting for something to happen. So if that isn't clear, post below, or give me a better example then I am coming up with at almost 1am :P.

Example Code

So the example code for this week is how every good programming book starts out, with the Hello World program. There is a command in GlovePIE called debug, which allows you to output some information to the place next to the Run/Stop button. So the debug command gets information by what you set it equal to, and then outputs it to the place I said. So to output Hello World! you simply type this line of code in a new script.

debug = "Hello World!"

Then you should see something like link -> this after you hit the run button. So test it out, and if this is your first script, point out to everyone how smart you are as you have now made the computer speak, thus taking your first step into creating a new form of AI...or you've just made the computer say hi ;).