Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
Collapse
Just Flight Community Forum
  1. Home
  2. Just Flight
  3. MSFS Products
  4. Black Square Add-Ons
  5. Baron Professional
  6. Help with an LUA script.. anyone?

Help with an LUA script.. anyone?

Scheduled Pinned Locked Moved Baron Professional
3 Posts 2 Posters 38 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MatzeH84
    wrote last edited by
    #1

    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
    end
    

    end

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jmarkows
      wrote last edited by
      #2

      @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?

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MatzeH84
        wrote last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users