Get Started
Okay! In our first steps... we will accomplish
several things at once
- We will learn a few Lua commands.
- We will create a Lua script (file).
- We will program FSUIPC to run the script manually.
- We will program FSUIPC to run the program automatically.
So let's open your Lua Library Reference and your editor.
If you tabulated your Library reference, go to the GoFlight (gfd) section.
On the first page you'll see a list of GoFlight modules. I best almost
everyone has at least a GFP8 or GFT8. All of those Module names are
Constant variables.
1. The first "command" we find on the next page is
gfd.BlankAll(). Type that into your editor.
2. Move down the page until you find
gfd.SetBright(model, unit, n). Here's our real introduction to
Constants and Variables.
Look at that command carefully and take note of the stuff
in the ( )... model, unit, n Those are the
parameters for the command. They indicate we need to put in values
that represent those items. For model, we use the constants listed on the first
page. If you have a GFT8, we'll use that. If not, try using GFP8. Go ahead and
type in the following...
gfd.SetBright(GFP8, unit, n)
Now what's this "unit" thing? It's the number of your GF
module. When computers count anything, they ALWAYS start with zero. Your trigger
may be called button #1, but it's actually button #0 (zero).
We are going to use the variable "unit" to represent the number zero, so add
the new line in your code so it looks like this...
gfd.BlankAll()
Unit = 0
gfd.SetBright(GFP8, unit, n)
Our last parameter is "n". We won't be using a Constant or
Variable, we are going to use a direct value of 15...
gfd.SetBright(GFP8, unit, 15)
No go back and "check your case".
Meaning, make sure the correct letters are Upper or Lower case. Lua commands
ARE CASE SENSITIVE!!! So far, all this does is blank all
the GF modules and set there brightness to 15 (full). But there's a big
difference between "setting the brightness" and "turning on a light". So let's
do that. Go back to your reference and find the command
gfd.SetLight(model, unit, id).
Go ahead and enter that command. Your script should look like this...
gfd.BlankAll()
Unit = 0
gfd.SetBright(GFP8, unit, n)
gfd.SetLight(model, unit, id)
Since we are using the constant GFP8 to tell FSUIPC which model to
operate, let's change "model" to "GFP8". You can leave "unit" alone since
we've already assigned unit to equal zero. But now we have a new
parameter... id. This is the number of the light, on the GF module.
Remember, everything starts at zero... so to change things up, let's make that a
one.
gfd.SetLight(GFP8, unit, 1)
You've just written your very first Lua script. Now
let's save that, with the filename "MyTestLua.Lua", into your FS/Modules
directory. Now run your FlightSim and start a flight so we can open the
FSUIPC GUI.
If you have a spare button, make a button assignment (as shown below) with
the control being "Lua MyTestLua". Now, when you press that button, it
will run that Lua script.
And again, if you can, choose another unused button and assign it to "Lua
Kill All".
You should find a copy of the file "MyLuaTest.Lua" in the
FLG Tutorials folder.
|