Welcome to Cockpitbuilders.com. Please login or sign up.

March 19, 2024, 02:41:23 AM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
49 Guests, 0 Users
Members
Stats
  • Total Posts: 59,638
  • Total Topics: 7,853
  • Online today: 65
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 0
Guests: 49
Total: 49

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

LUA Momentary Pushbuttons

Started by erocfx, March 03, 2021, 07:43:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

erocfx

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?

Trevor Hale

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
Trevor Hale

Owner
http://www.cockpitbuilders.com

Director of Operations
Worldflight Team USA
http://www.worldflightusa.com

VATSIM:

erocfx

#2
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

Trevor Hale

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
Trevor Hale

Owner
http://www.cockpitbuilders.com

Director of Operations
Worldflight Team USA
http://www.worldflightusa.com

VATSIM:

KyleH

#4
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.
Kyle

Chief Pilot
Worldflight Team USA
http://www.worldflightusa.com

Trevor Hale

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
Trevor Hale

Owner
http://www.cockpitbuilders.com

Director of Operations
Worldflight Team USA
http://www.worldflightusa.com

VATSIM:

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate