Multiple msfs_rpn commands

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
InertiaM
Posts: 17
Joined: Wed Feb 12, 2025 6:34 pm

Multiple msfs_rpn commands

#1 Post by InertiaM »

If I put multiple msfs_rpn commands into a single LUA function, only the last msfs_rpn line executes. I know I can work around by combining them all into a single msfs_rpn command, but any idea as to why this happens?

Code: Select all

function test()
  msfs_rpn("1 (>B:UNKNOWN_CHOCKS_Set)")
  msfs_rpn("1 (>B:UNKNOWN_COVER_ENGINE_Set)")
  msfs_rpn("1 (>B:UNKNOWN_COVER_PITOT_Set)")
  msfs_rpn("1 (>B:UNKNOWN_COVER_STATIC_PORT_Set)")  --< only the LAST msfs_rpn line executed
end

FlightEngineer1
Posts: 196
Joined: Fri Mar 08, 2024 9:21 am
Location: Germany

Re: Multiple msfs_rpn commands

#2 Post by FlightEngineer1 »

@InertiaM
It's just a guess. Because the RPN commands are fired every fraction of a second, the MSFS parser only executes the last one. The MSFS SDK defines the RPN commands as follows:

When the RPN script parser comes across a value, it pushes it onto the top of the stack.

When the script parser comes across an operator, it pops the number of operands that the operator works on (usually one or two values) from the stack.

Whatever value is left on top of the stack at the end of the execution is the result of the calculated expression.

In a batch file exists a command to force the Compiler to execute one line and then the next lineof code.

FlightEngineer1
Posts: 196
Joined: Fri Mar 08, 2024 9:21 am
Location: Germany

Re: Multiple msfs_rpn commands

#3 Post by FlightEngineer1 »

@InertiaM

Hi,
This is also called asynchronous command execution. To prevent this from happening, you need to add some time between the commands. There are two ways to do this. The best one for me is the timer method, which is often used elsewhere. I've created a small code example for it. I normally use the red button to execute Shift+C. In the attached SIFF file, it now sets all the covers for lazy pilots so they can get to the bar faster. :)

Code: Select all

local cover_commands = {
    "1 (>B:UNKNOWN_CHOCKS_Set)",
    "1 (>B:UNKNOWN_COVER_ENGINE_Set)",
    "1 (>B:UNKNOWN_COVER_PITOT_Set)",
    "1 (>B:UNKNOWN_COVER_STATIC_PORT_Set)"
}

local index = 1  -- Start with the first command

function check_press_red()
                                         --os.execute(yourfilepath) in my aircraft you can jump in
                                         -- and out with the help of autohotkey script, see above
    if index <= #cover_commands then
        msfs_rpn(cover_commands[index])  -- send command
        index = index + 1                -- next command
        cover_timer=timer_start(100, 0,check_press_red) -- after 100ms next command
    else
        timer_stop(cover_timer)
        index= 1
    end
end



function check_release_red()
-- do nothing
end

check_button =button_add("red_button.png", "red_button_pressed.png", 45, 280, 60, 60, check_press_red,check_release_red)
FS2024 - RPM Test.siff
(136.73 KiB) Downloaded 26 times

InertiaM
Posts: 17
Joined: Wed Feb 12, 2025 6:34 pm

Re: Multiple msfs_rpn commands

#4 Post by InertiaM »

@FlightEngineer1

Thanks for that. I was trying to follow a checklist on which covers to remove, hence doing them individually. Once I’m bored, I’ll upgrade to your code!

Quick question(s) - I take it because cover_timer is not declared locally, there is no need to confirm if the previous cover_timer has executed and therefore terminated.

In other programs, I’ve always tended to use “released” rather than “pressed”, to avoid multiple functions firing if the button is kept pressed. Do I not need to worry with AM?

FlightEngineer1
Posts: 196
Joined: Fri Mar 08, 2024 9:21 am
Location: Germany

Re: Multiple msfs_rpn commands

#5 Post by FlightEngineer1 »

@InertiaM
In the Siff file you have four buttons for removing or reattaching each individual cover. That's how I do it. I use the red button so I don't have to press Shift+C on the keyboard to get on the plane. I've repurposed the red button for you. Whether you call it press or release doesn't matter, as long as you know what you're doing. You can also name it anything else. You just can't have two functions with the same name, otherwise you can call anything you want.You don't not need to worry with AM. The timer doesn't need a local.

InertiaM
Posts: 17
Joined: Wed Feb 12, 2025 6:34 pm

Re: Multiple msfs_rpn commands

#6 Post by InertiaM »

From todays MSFS2024 Beta Update bug fixes :-
Preflight

Added Binding TOOLS QUICK PREFLIGHT which removes the covers from the aircraft
Means I can undo all my code :lol:

FlightEngineer1
Posts: 196
Joined: Fri Mar 08, 2024 9:21 am
Location: Germany

Re: Multiple msfs_rpn commands

#7 Post by FlightEngineer1 »

@InertiaM

Hi,

Based on your post, I checked the variables in the new beta. This is the code for boarding and disembarking the Vision Jet, for example:

Code: Select all

-------------------------------------------  RED Enter and EXIT THE AIRCRAFT   ----------------------------------------------
local avatar

function check_press_red()
    if avatar == true then
        msfs_rpn(" (>B:SF50_EXT_PILOT_SIT_Set)")
    else
        msfs_rpn(" (>B:SF50_INT_PILOT_EXIT_Set)")
    end
end 

check_button =button_add("red_button.png", "red_button_pressed.png", 115, 230, 60, 60, check_press_red)

msfs_variable_subscribe("IS AVATAR","BOOL", function(ava)
avatar= ava
end)
The code used in your instrument

Code: Select all

msfs_rpn("1 (>L:1:ENTER_AIRCRAFT, true)")
doesn't always work. Although the "scoped L var" variable changes in the behavior tool, sometimes nothing happens.

InertiaM
Posts: 17
Joined: Wed Feb 12, 2025 6:34 pm

Re: Multiple msfs_rpn commands

#8 Post by InertiaM »

@FlightEngineer1

Thanks for that, I’ll look at the variables you mentioned.

Separately, I found a bug(!) in MSFS2024 where the variable identifying what view is being used, does not update when the pilot exits the plane. I don’t have the Beta, so I’m not going to change any code until they release the next version.

FlightEngineer1
Posts: 196
Joined: Fri Mar 08, 2024 9:21 am
Location: Germany

Re: Multiple msfs_rpn commands

#9 Post by FlightEngineer1 »

@InertiaM

Hi,
MSFS 2024 (not beta) already has the variable:
"IS AVATAR" (Boolean. This returns either 1 (TRUE) or 0 (FALSE) to indicate whether the user is in "Avatar" mode or not). This makes it easy to determine in AM whether the avatar is in or out of the aircraft.

The C-172 doesn't have the B variables that are already available on the Vision Jet or the TBM 930 to get in or out of the aircraft.

You actually have to use your "scoped L var." Unfortunately, strange things happen then that are different from other variables. If you need the value 1 to get in or out of the aircraft, you need the value 0 the next time you call it. Therefore, my new script now switches the value between 0 and 1 every time you click the button, depending, of course, on whether the ENTER or EXIT function is used.

Code: Select all

------------------------- ENTER and EXIT THE AIRCRAFT -------------------------------------------------------
ava_txt=txt_add("ENTER AC", "font:roboto_bold.ttf; size:24; color: white; halign:center;",25, 290, 100, 20)

local avatar
local entervalue = 1
local exitvalue = 1

function check_press_red()

   if avatar == true then
       msfs_rpn(entervalue.." (>L:1:ENTER_AIRCRAFT)")
       entervalue = 1-entervalue
   else
       msfs_rpn(exitvalue.." (>L:1:EXIT_AIRCRAFT)")
       exitvalue = 1-exitvalue
   end
end 

check_button =button_add("red_button.png", "red_button_pressed.png", 45, 310, 60, 60, check_press_red)

msfs_variable_subscribe("IS AVATAR","BOOL", function(ava)
    avatar= ava
    if ava then
        txt_set(ava_txt,"ENTER AC")
    else
        txt_set(ava_txt,"LEAVE AC")
    end

end)

Post Reply