Help with an LUA script.. anyone?
-
I'm trying to use the EDM using only two physical buttons, like in real life. I'm using FSUIPC, and assigning all the functions (short press, long press, both press) to individual buttons works well (so using 5 individual hardware inputs).
As I have no idea of LUA scripting, I asked ChatGPT, but it does not work. Maybe someone with a deeper knowledge could have a look at this.. I'd be grateful:
-- JPI_DualButton_Param.lua
-- Parameter 1 -> Taste A press
-- Parameter -1 -> Taste A release
-- Parameter 2 -> Taste B press
-- Parameter -2 -> Taste B release-- ============= KONFIGURATION =================
hvarA_short = "bksq_JpiButton_1_L_Short"
hvarA_long = "bksq_JpiButton_1_L_Long"
hvarB_short = "bksq_JpiButton_1_R_Short"
hvarB_long = "bksq_JpiButton_1_R_Long"
hvarAB_long = "bksq_JpiButton_1_B_Long"longpress_ms = 2000
-- ============= INTERN ==============
pressedA = false
pressedB = false
startA = 0
startB = 0-- HVAR Setter
local function setHVar(name)
pcall(function()
ipc.writeSTR("H:" .. name, "")
end)
end-- Prüfen ob beide >= longpress
local function bothLong(now)
if not (pressedA and pressedB) then return false end
return (now - startA >= longpress_ms) and (now - startB >= longpress_ms)
end
-- HAUPTFUNKTION – wird per LuaValue(Parameter) aus FSUIPC aufgerufen
function ipcPARAM(param)
local now = ipc.elapsedtime() ---------------------------------------------------------------- -- TASTE A ---------------------------------------------------------------- if param == 1 then -- A pressed pressedA = true startA = now elseif param == -1 then -- A released local dur = now - startA if bothLong(now) then setHVar(hvarAB_long) else if dur >= longpress_ms then setHVar(hvarA_long) else setHVar(hvarA_short) end end pressedA = false startA = 0 end ---------------------------------------------------------------- -- TASTE B ---------------------------------------------------------------- if param == 2 then -- B pressed pressedB = true startB = now elseif param == -2 then -- B released local dur = now - startB if bothLong(now) then setHVar(hvarAB_long) else if dur >= longpress_ms then setHVar(hvarB_long) else setHVar(hvarB_short) end end pressedB = false startB = 0 endend
-
@MatzeH84 From rubbing the sleep from my eyes or the scattering of German (I think) throughout, I'm having trouble figuring out what you're trying to do here.
Are you trying to use the script to send a different input based on which of your 5 hardware buttons you press?
-
Basically we have 5 Hvars now. Left short press, left long press, right short press, right long press and both buttons long press. I have assigned them individually to 5 buttons via FSUIPC and that works.
However I would like to try to use only two buttons and use the script to activate different Hvars depending on if the button is pressed momentarily or held (or if both buttons are pressed together), in order to operate the EDM as it would be in the real unit.