| |
Cleaning Up
Referring to the Last chapter's Lua file named "PitotHeat.Lua", this is what
we had...
function PitotHeat(offset, value)
model = GFT8
unit = 0
id = 1
if value == 1 then
gfd.SetLight(model, unit, id)
else
gfd.ClearLight(model, unit, id)
end
end
event.offset("029C", "UB", "PitotHeat")
If your comfortable with remembering which parameters are
for what we can slim down the code and instead of variables, we can use direct
values as shown below...
function PitotHeat(offset, value)
if value == 1 then
gfd.SetLight(GFT8,
0, 1)
else
gfd.ClearLight(GFT8,
0, 1)
end
end
event.offset("029C", "UB", "PitotHeat")
If you'd like to keep them as is, that's fine. It
won't make any difference to FSUIPC. but let me show you how to make "comments'
in your code.
function PitotHeat(offset, value)
-- Beginning of the function
if value == 1 then -- Checks to
see if value equals one
gfd.SetLight(GFT8,
0, 1)
-- Turns ON light#1, of unit#0 on the GFT8
else
gfd.ClearLight(GFT8,
0, 1)
-- Turns OFF light#1, of unit#0 on the GFT8
end -- end of the "if...then"
statement
end -- end of the function
event.offset("029C", "UB", "PitotHeat")
Anything after the two "--" will be ignored by FSUIPC. If
you do want to slim down your code, but don't want to forget what the parameters
are you can modify your code like this...
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")
There, now that's nice and neat and you can see what the
parameters are for.
| |
|