FSUIPC: Lua Tutorial |
|
Assignments So now that we can turn lights on and off, how do we get FS to turn the lights on and off using our Lua? Well we don't have to. I still recommend using FSUIPC to make a function assignments to your GF module. But just to cover everything, open up your "PitotHeat.Lua" file. Here's what we have... function PitotHeat(offset, value) We are going to add another function called "SetPitotHeat" as shown below... function SetPitotHeat(model, unit) Along with another "event" command at the very end... event.gfd(GFT8, 0, "SetPitotHeat") So our file should now look like this... function PitotHeat(offset, value) Let's brake down the new code beginning with the new event... event.gfd(GFT8, 0, "SetPitotHeat") What this does is it monitors your GFT8, #0 for any changes in switch positions. If any changes are detected, it runs the function named "SetPitotHeat". Now let's go look at our new function... function SetPitotHeat(model, unit) In the "function" statement line, the parameters are "model" & "unit". These variable assignments are made by the event.gfd, "GFT8, 0". Then we need to get the status of all the switches... gfd.GetValues(model, unit) That statement, then allows the following command to work correctly... if gfd.TestButton(1) then This will, based on the "GetValues" test to see if switch #1 is ON. If so, it runs our next command ipc.writeUB("029C",1) That command will write the value of 1 to the Unsigned Byte at address "029C" thereby turning ON the Pitot Heat. Pretty cool huh? |
|
|