Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi there,

I'm trying to call the function 'Armrest_Toggle' with a button assigned through FSUIPC as follows:

if ipcPARAM == 0 then

	Armrest_Toggle()

end

local function Armrest_Toggle()
    ipc.writeLvar(nToggleVal(ipc.readLvar("L:Twot_Armrest"), 0, 1))
end

local function nToggleVal(nCurrVal, nVal1, nVal2)
	if nCurrVal == nVal1 then
		return nVal2
	else
		return nVal1
	end
end

I'm tracing the changes in LVars and when I press the assigned button, I get this error:

273111 *** LUA Error: ...Games\Microsoft Flight Simulator X\Modules\dhc-6.lua:26: attempt to call global 'Armrest_Toggle' (a nil value)

And here is the content of FSUIPC.ini, as relates to the particular aircraft I've loaded into the sim:

[JoyNames]
AutoAssignLetters=No
0=X52 Pro Flight Controller
0.GUID={A1946F60-C51A-11E6-8005-444553540000}

[Profile.DHC-6]
1=Aerosoft DHC-6

[Buttons.DHC-6]
0=P0,1,CL1:R,0 ; armrest toggle 	-{Lua dhc-6}-

[General]
ShortAircraftNameOk=Substring

[LuaFiles]
1=dhc-6
2=ipcReady
3=linda

 

I wonder what can cause this error? Thanks in advance!!!

FSUIPC4.log

Posted

Hi,

in C/C++ you need a forward declaration to have the definition below the actual call. So you write bottom up if you don't do this, means you might need to have the local function Armrest_Toggle()... above the calling part.

The error says you are looking for a global function, that means your actual function is not visible when you call it.

Thomas

  • Upvote 1
Posted

Thank you, Thomas!!! Strange, I thought calling functions was just a matter of proper environment definition (local or global), but direction of declaration is smth new for me...

I'll try your suggestion and return to this thread.

And Happy New Year!!!

Posted

I tried this to no avail yet...

function nToggleVal(nCurrVal, nVal1, nVal2)
	if nCurrVal == nVal1 then
		return nVal2
	else
		return nVal1
	end
end

function Armrest_Toggle()
    ipc.writeLvar(nToggleVal(ipc.readLvar("L:Twot_Armrest"), 0, 1))
end

if ipcPARAM == 0 then

	Armrest_Toggle()
	
end

FSUIPC.ini is unchanged - FSUIPC recognizes the button OK. The problem is associated with function call I think. But I don't know why the above syntax doesn't work... :(

Posted

Hi,

looking at

function Armrest_Toggle()
    ipc.writeLvar(
nToggleVal(ipc.readLvar("L:Twot_Armrest"), 0, 1))
end

the write should of course have the L:"LVariablename" you want to write to but you don't supply any, just the returned nVal1 !?

ipc.writeLvar(“name”, n)

Thomas

Posted

OMG, it was so obvious... This one works finally:

function Armrest_Toggle()
    ipc.writeLvar("L:Twot_Armrest", nToggleVal(ipc.readLvar("L:Twot_Armrest"), 0, 1))
end

Thank you VERY much for the hint, Thomas!!!

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.