FSUIPC: Lua Tutorial
For Microsoft Flight Simulator and GoFlight Equipment

 

Home
About Lua
Executing Code
Binary
Hexadecimal
Bits & Bytes
Memory Offsets
Variables
The Code
The Editor
Get Started
FlightSim
Cleaning Up
Assignments

 

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)
    if value == 1 then
        gfd.SetLight(GFT8, 0, 1) -- (model, unit, id)
    else
        gfd.ClearLight(GFT8, 0, 1)
    end
end
event.offset("029C", "UB", "PitotHeat")

    We are going to add another function called "SetPitotHeat" as shown below...

function SetPitotHeat(model, unit)
    gfd.GetValues(model, unit)
    if gfd.Buttons(1) == 2 then
        ipc.writeUB("029C",1)
    else
        ipc.writeUB("029C",0)
    end
end
 

    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)
    model = GFT8
    unit = 0
    id = 1
    gfd.SetBright(model, unit, 15)
    if value == 1 then
        gfd.SetLight(model, unit, id)
    else
        gfd.ClearLight(model, unit, id)
    end
end
function SetPitotHeat(model, unit)
    gfd.GetValues(model, unit)
    if gfd.TestButton(1) then
        ipc.writeUB("029C",1)
    else
        ipc.writeUB("029C",0)
    end
end
event.offset("029C", "UB", "PitotHeat")
event.gfd(GFT8, 0, "SetPitotHeat")

    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)
    gfd.GetValues(model, unit)
    if gfd.TestButton(1) then
        ipc.writeUB("029C",1)
    else
        ipc.writeUB("029C",0)
    end
end

    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?

 


Written by
Joseph "Skittles" Cardana
skittles(at)anadrac.com
Updated: 2011-08-25 07:49