Jump to content
The simFlight Network Forums

Recommended Posts

Posted

In the "FSUIPC Lua Library" manual, in the event.offset section it states...

The function is also executed initially, when the plugin is first run, in order to initialise things. This saves using an explicit call to do the same.

My question is... Does the function itself get executed or do the event.offset commands get executed?

Here's why I'm asking, I have 8 event.offsets which call the same function. So if the initial execution is actually done by the event.offset commands, it would run the function 8 times, right?

gfd.GetValues(GFT8, 1)
-- GFT8 Module 1
function GFModule(offset, value)
	unit = 1
  	gfd.GetValues(GFT8, unit)
  	if gfd.TestButton(0) then -- BATTERY MASTER
  	    ipc.set("MastBatt", 1)
	    gfd.SetLight(GFT8, unit, 0)
	    ipc.writeUB("3102", 1)
        ipc.runlua("GF-T80")
  	else
  	    ipc.set("MastBatt", 0)
	    gfd.ClearLight(GFT8,unit,0)
	    ipc.writeUB("3102", 0)
	    gfd.BlankAll()
        ipc.runlua("GF-T80")
  	end
--  	gfd.GetValues(GFT8, unit) -- ALTERNATOR MASTER
  	if gfd.TestButton(1) then
        if ipc.get("MastBatt") == 1 then
	        gfd.SetLight(GFT8, unit, 1)
		end
		ipc.writeUB("3101", 1)
  	else
	    gfd.ClearLight(GFT8,unit,1)
	    ipc.writeUB("3101", 0)
  	end
--  	gfd.GetValues(GFT8, unit) -- AVIONICS MASTER
  	if gfd.TestButton(2) then
  	    ipc.set("AviMast", 1)
        if ipc.get("MastBatt") == 1 then
		    gfd.SetLight(GFT8, unit, 2)
		end
	    ipc.writeUB("3103", 1)
	    ipc.runlua("GF-Altimeter")
	    ipc.runlua("GF-Clock")
        ipc.runlua("GF-HSaD")
  	else
  	    ipc.set("AviMast", 0)
	    gfd.ClearLight(GFT8,unit,2)
	    ipc.writeUB("3103", 0)
	    ipc.runlua("GF-Clock")
	    ipc.runlua("GF-Altimeter")
        ipc.runlua("GF-HSaD")
  	end
--  	gfd.GetValues(GFT8, unit) -- NAV GPS/VOR
  	if gfd.TestButton(3) then
        if ipc.get("MastBatt") == 1 then
	        gfd.SetLight(GFT8, unit, 3)
		end
		ipc.writeUB("132C", 1)
  	else
	    gfd.ClearLight(GFT8,unit,3)
	    ipc.writeUB("132C", 0)
  	end
--  	gfd.GetValues(GFT8, unit) -- FUEL PUMP
  	if gfd.TestButton(4) then
        if ipc.get("MastBatt") == 1 then
	        gfd.SetLight(GFT8, unit, 4)
		end
	    ipc.writeUB("3104", 1)
  	else
	    gfd.ClearLight(GFT8,unit,4)
	    ipc.writeUB("3104", 0)
  	end
--  	gfd.GetValues(GFT8, unit) -- SPOILER ARM
  	if gfd.TestButton(5) then
        if ipc.get("MastBatt") == 1 then
	        gfd.SetLight(GFT8, unit, 5)
	    end
	    ipc.writeUB("0BCC", 1)
  	else
	    gfd.ClearLight(GFT8,unit,5)
	    ipc.writeUB("0BCC", 0)
  	end
--  	gfd.GetValues(GFT8, unit) -- AUTO FEATHER
  	if gfd.TestButton(6) then
        if ipc.get("MastBatt") == 1 then
		    gfd.SetLight(GFT8, unit, 6)
		end
	    ipc.writeUB("2E88", 1)
  	else
	    gfd.ClearLight(GFT8,unit,6)
	    ipc.writeUB("2E88", 0)
  	end
--  	gfd.GetValues(GFT8, unit) -- Parking Brake
  	if gfd.TestButton(7) then
        if ipc.get("MastBatt") == 1 then
	        gfd.SetLight(GFT8, unit, 7)
		end
		    ipc.writeUB("0BC8", 32768)
  	else
	    gfd.ClearLight(GFT8,unit,7)
	    ipc.writeUB("0BC8", 0)
  	end
end
--==============================================================================
-- POWER SWITCHES / GF-T8 MODULE 1
event.offset("3102", "UB", "GFModule")-- Battery Master
event.offset("3101", "UB", "GFModule")-- Alternator Master
event.offset("3103", "UB", "GFModule")-- Avionics Master
event.offset("132C", "UD", "GFModule")-- NAV GPS/VOR
event.offset("3104", "UB", "GFModule")-- Fuel Pump
event.offset("0BCC", "SD", "GFModule")-- Spoiler Arm
event.offset("2E88", "UD", "GFModule")-- Auto Feather
event.offset("0BC8", "SW", "GFModule")-- Parking Brake

[uPDATE:]

I added a ipc.log command. This is what was logged...

********* LUA: "GF-T81" Log [from FSUIPC version 3.997k] *********

36094 System time = 10/08/2011 15:22:10, FS2004 time = 10:50:06 (16:50Z)

36094 LUA: beginning "D:\FS2004-FS9\Modules\GF-T81.lua"

36094 LUA: GF-T8 / Mod1 executed

36953 LUA: GF-T8 / Mod1 executed

37719 LUA: GF-T8 / Mod1 executed

38562 LUA: GF-T8 / Mod1 executed

39484 LUA: GF-T8 / Mod1 executed

40250 LUA: GF-T8 / Mod1 executed

41062 LUA: GF-T8 / Mod1 executed

41828 LUA: GF-T8 / Mod1 executed

So I answered my own question... but is it supposed to do this?

Posted

In the "FSUIPC Lua Library" manual, in the event.offset section it states...

My question is... Does the function itself get executed or do the event.offset commands get executed?

The function is executed once when the calling event is executed. That's the only time the function is called without the nominated event actually occurring. It is to provide the initial values.

What else could it possibly mean? I can see no other possible interpretation!

Here's why I'm asking, I have 8 event.offsets which call the same function. So if the initial execution is actually done by the event.offset commands, it would run the function 8 times, right?

Yes, of course, once for each of the associated events, and with the data relevant to those events.

Again, I ask, what else could it possibly mean? I fail to see how it is ambiguous.

[uPDATE:]

I added a ipc.log command. This is what was logged...

So I answered my own question... but is it supposed to do this?

What else could it do? You should have included the "offset" and "value" parameters the function was called with in the Logging, then you'd have seen how obvious it is!

Pete

Posted

I read these two quotes as saying two different things

The function is also executed initially, when the plugin is first run, in order to initialise things.
The way I understood it to mean was that the function was executed without being called by the event.offset during the initial run.
The function is executed once when the calling event is executed.

I'm probably wrong, but I think there's a difference between executing a function and calling a function.

But even in my own VB programs, functions don't execute unless called, I just wanted clarification.

Thanks,

Joe

Posted

The way I understood it to mean was that the function was executed without being called by the event.offset during the initial run.

How could it do that? It won't have any knowledge of the function name unless it is provided (i.e. by the event call), and, further, would have no idea what parameter values to pass. And how would it know which functions were for events and which just functions you are using for something else? It would obviously have to execute the event function first, for all these reasons.

And what would be the point? How would it "initialise things", as per the stated purpose of executing the function?

Not only that, but please notice that the statement you are quoting appears in the description of the event facilities.

I can't see how it could be interpreted like that, sorry.

I'm probably wrong, but I think there's a difference between executing a function and calling a function.

Not really. Generally functions are executed, whilst procedures are called. That's the normal use of those words. But it isn't a rigid rule and it really makes no difference. "Execution" means the lines in it are obeyed.

Regards

Pete

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.