If I want to use a momentary pushbutton to toggle autopilot for example, how would I do that? There is an individual event ID for on and off.
If I am using a string variable from an arduino and this code:
if
(string.find(datastring, "S161")) then
ipc.control(65792,0)
end
Do I query it to get the state first then on pushbutton toggle it? How would I do that?
Eric,
ipc.control(65792,0) If you read in the FSUIPC Lua documentation you will find that 65792 is assigned to a function inside Flightsim / FSUIPC.
Look up the ipc.control number for the function you are looking for for example (Toggle Autopilot)
Your string is looking for (When input 16 is High) then do that IPC.Control function.
You can also do something like this if the ipc control has only on or off.
if (string.find(datastring, "S161")) and AP==0 then
ipc.control(65792,0)
AP=1
else
ipc.control(65793,0)
AP=0
end
This would be the case if (65792) Was in fact Auto pilot on and (65793) was autopilot off
Trev
Thanks Trevor, after posting I found the Autopilot Master event ID :D But the code you posted is what I am looking for.
Do I have to assign AP as a variable at the head of the script?
Also, it keeps putting out the else event anytime I use another button
Honestly, I can't remember, either LUA or the Sketch one you have to predefine it and one you don't
If it doesn't parse, then predefine it at the top.
Trev
Quote from: erocfx on March 04, 2021, 01:21:51 PM...
Also, it keeps putting out the else event anytime I use another button
It would. There is a bug the way Trev posted it. You need something more like this:
Quoteif (string.find(datastring, "S161"))
if AP==0 then
ipc.control(65792,0)
AP=1
else
ipc.control(65793,0)
AP=0
end
end
Please note I'm not familiar with the specifics of LUA syntax, I'm a c programmer, but the same programming logic will apply.
Yes, Kyle is right, You can do the second condition in the top line if it is inside the () I screwed that up, but Kyles way is cleaner.
Trev