rustam Posted December 30, 2016 Report Posted December 30, 2016 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
Thomas Richter Posted December 31, 2016 Report Posted December 31, 2016 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 1
rustam Posted December 31, 2016 Author Report Posted December 31, 2016 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!!!
rustam Posted January 1, 2017 Author Report Posted January 1, 2017 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... :(
Thomas Richter Posted January 1, 2017 Report Posted January 1, 2017 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
rustam Posted January 1, 2017 Author Report Posted January 1, 2017 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!!!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now