FS2020_variable_subscribe
-
- Posts: 15
- Joined: Fri Mar 20, 2020 11:13 pm
FS2020_variable_subscribe
Hi community
Sorry in advance to annoy you
i don't understand why the FS2020_variable_subscribe works for line 30 (twice variable request) and not for 31 & 32 (individual variable request which return "Not allowed nill value" error)
i make a RPN script in LORBY Axis & Ohs to read the 2 variables and it returns 0 or 1 for both depending of push button action i make on the MCP hardware or by click on the Aircraft MCP in FS2020 Can you help a stupid Air Manager LUA Scripter ?
Thanks & regards
Thierry
Air Manager 4.02 /FS2020 Last version / Windows 10
Sorry in advance to annoy you
i don't understand why the FS2020_variable_subscribe works for line 30 (twice variable request) and not for 31 & 32 (individual variable request which return "Not allowed nill value" error)
i make a RPN script in LORBY Axis & Ohs to read the 2 variables and it returns 0 or 1 for both depending of push button action i make on the MCP hardware or by click on the Aircraft MCP in FS2020 Can you help a stupid Air Manager LUA Scripter ?
Thanks & regards
Thierry
Air Manager 4.02 /FS2020 Last version / Windows 10
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: FS2020_variable_subscribe
Hi,
Because your callbacks are within a conditional function.
Post the code in the </> code brackets above and i will fix it for you,
Keith
Because your callbacks are within a conditional function.
Post the code in the </> code brackets above and i will fix it for you,
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
-
- Posts: 15
- Joined: Fri Mar 20, 2020 11:13 pm
Re: FS2020_variable_subscribe
Hi Keith , thanks
here the LUA script
</>
IMG_AP_Back_ON = img_add("Power ON.png", 0 , 0, 1479 , 319)
IMG_AP_Back_OFF = img_add("Power OFF.png", 0, 0, 1479 , 319)
TXT_AutoPilot_Master = txt_add("","font:digital-7-mono.ttf; size:50; color: White; halign:left;", 0, 0, 500, 100 , true)
TXT_AutoPilot_FD = txt_add("","font:digital-7-mono.ttf; size:50; color: White; halign:left;", 0, 105 , 500, 100 , true)
function F_ELECTRICAL_MASTER_BATTERY_and_AVIONICS_MASTER_SWITCH_callback(V_Electrical_Master_Battery, V_Avionics_Master_Switch)
if V_Electrical_Master_Battery == true and V_Avionics_Master_Switch == true then
visible(IMG_AP_Back_ON, true)
visible(IMG_AP_Back_OFF, false)
function F_AUTOPILOT_MASTER_callback(V_Autopilot_Master)
if V_Autopilot_Master == true then
txt_set(TXT_AutoPilot_Master, "AP ON")
else
txt_set(TXT_AutoPilot_Master, "")
end
end
function F_AUTOPILOT_FD_callback(V_Autopilot_FD)
if V_Autopilot_FD == true then
txt_set(TXT_Autopilot_FD, "FD ON")
else
txt_set(TXT_Autopilot_FD, " ")
end
end
else
visible(IMG_AP_Back_ON, false)
visible(IMG_AP_Back_OFF, true)
txt_set(TXT_AutoPilot_Master, " ")
txt_set(TXT_Autopilot_FD, " ")
end
end
fs2020_variable_subscribe("ELECTRICAL MASTER BATTERY", "Boolean", "AVIONICS MASTER SWITCH", "Boolean", F_ELECTRICAL_MASTER_BATTERY_and_AVIONICS_MASTER_SWITCH_callback)
fs2020_variable_subscribe("AUTOPILOT MASTER", "Boolean", F_AUTOPILOT_MASTER_callback)
fs2020_variable_subscribe("AUTOPILOT FLIGHT DIRECTOR ACTIVE", "Boolean", F_AUTOPILOT_FD_callback)
</>
here the LUA script
</>
IMG_AP_Back_ON = img_add("Power ON.png", 0 , 0, 1479 , 319)
IMG_AP_Back_OFF = img_add("Power OFF.png", 0, 0, 1479 , 319)
TXT_AutoPilot_Master = txt_add("","font:digital-7-mono.ttf; size:50; color: White; halign:left;", 0, 0, 500, 100 , true)
TXT_AutoPilot_FD = txt_add("","font:digital-7-mono.ttf; size:50; color: White; halign:left;", 0, 105 , 500, 100 , true)
function F_ELECTRICAL_MASTER_BATTERY_and_AVIONICS_MASTER_SWITCH_callback(V_Electrical_Master_Battery, V_Avionics_Master_Switch)
if V_Electrical_Master_Battery == true and V_Avionics_Master_Switch == true then
visible(IMG_AP_Back_ON, true)
visible(IMG_AP_Back_OFF, false)
function F_AUTOPILOT_MASTER_callback(V_Autopilot_Master)
if V_Autopilot_Master == true then
txt_set(TXT_AutoPilot_Master, "AP ON")
else
txt_set(TXT_AutoPilot_Master, "")
end
end
function F_AUTOPILOT_FD_callback(V_Autopilot_FD)
if V_Autopilot_FD == true then
txt_set(TXT_Autopilot_FD, "FD ON")
else
txt_set(TXT_Autopilot_FD, " ")
end
end
else
visible(IMG_AP_Back_ON, false)
visible(IMG_AP_Back_OFF, true)
txt_set(TXT_AutoPilot_Master, " ")
txt_set(TXT_Autopilot_FD, " ")
end
end
fs2020_variable_subscribe("ELECTRICAL MASTER BATTERY", "Boolean", "AVIONICS MASTER SWITCH", "Boolean", F_ELECTRICAL_MASTER_BATTERY_and_AVIONICS_MASTER_SWITCH_callback)
fs2020_variable_subscribe("AUTOPILOT MASTER", "Boolean", F_AUTOPILOT_MASTER_callback)
fs2020_variable_subscribe("AUTOPILOT FLIGHT DIRECTOR ACTIVE", "Boolean", F_AUTOPILOT_FD_callback)
</>
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: FS2020_variable_subscribe
Hi,
To post code like I have done here. Click on the </> button and place your code between the code boxes
.
I do not have MSFS2020 to test but this should work. I used your logic, So you might have to change that. Let me know if you do not understand what I have done or need more help.
Keith
To post code like I have done here. Click on the </> button and place your code between the code boxes
.
I do not have MSFS2020 to test but this should work. I used your logic, So you might have to change that. Let me know if you do not understand what I have done or need more help.
Code: Select all
IMG_AP_Back_ON = img_add("Power ON.png", 0 , 0, 1479 , 319)
IMG_AP_Back_OFF = img_add("Power OFF.png", 0, 0, 1479 , 319)
TXT_AutoPilot_Master = txt_add("","font:digital-7-mono.ttf; size:50; color: White; halign:left;", 0, 0, 500, 100 , true)
TXT_AutoPilot_FD = txt_add("","font:digital-7-mono.ttf; size:50; color: White; halign:left;", 0, 105 , 500, 100 , true)
fs2020_variable_subscribe("ELECTRICAL MASTER BATTERY", "Boolean", "AVIONICS MASTER SWITCH", "Boolean", "AUTOPILOT MASTER", "Boolean","AUTOPILOT FLIGHT DIRECTOR ACTIVE", "Boolean",function(mast_bat,mast_switch,auto_master,FD_active)
--Show annuntuators
visible(IMG_AP_Back_ON, mast_bat == true and mast_switch == true )
visible(IMG_AP_Back_OFF, mast_bat == false or mast_switch== false)
--Set text if AutoPilot is on or off
if mast_bat == true and mast_switch == true then
if auto_master == true then
txt_set(TXT_AutoPilot_Master, "AP ON")
else
txt_set(TXT_AutoPilot_Master, "")
end
--Set text if FlightDirector is on or off
if FD_active == true then
txt_set(TXT_Autopilot_FD, "FD ON")
else
txt_set(TXT_Autopilot_FD, " ")
end
else
txt_set(TXT_AutoPilot_Master, " ")
txt_set(TXT_Autopilot_FD, " ")
end
end)
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
-
- Posts: 15
- Joined: Fri Mar 20, 2020 11:13 pm
Re: FS2020_variable_subscribe
Hi Keith
Your script with a single fs2020_variable_subscribe("ELECTRICAL MASTER BATTERY", "Boolean", "AVIONICS MASTER SWITCH", "Boolean", "AUTOPILOT MASTER", "Boolean","AUTOPILOT FLIGHT DIRECTOR ACTIVE", "Boolean",function(mast_bat,mast_switch,auto_master,FD_active) works perfectly
in the same time , a french friend looking to my SOS called me and gave me also this solution with a single function which works too
function F_AUTOPILOT_callback(V_Electrical_Master_Battery, V_Avionics_Master_Switch, V_Autopilot_Master, V_Autopilot_FD )
.....
End
fs2020_variable_subscribe("ELECTRICAL MASTER BATTERY", "Boolean", "AVIONICS MASTER SWITCH", "Boolean", "AUTOPILOT MASTER", "Boolean", "AUTOPILOT FLIGHT DIRECTOR ACTIVE", "Boolean" , F_AUTOPILOT_callback)
Many thanks together for your help, i can continue
Best regards
Thierry
Your script with a single fs2020_variable_subscribe("ELECTRICAL MASTER BATTERY", "Boolean", "AVIONICS MASTER SWITCH", "Boolean", "AUTOPILOT MASTER", "Boolean","AUTOPILOT FLIGHT DIRECTOR ACTIVE", "Boolean",function(mast_bat,mast_switch,auto_master,FD_active) works perfectly
in the same time , a french friend looking to my SOS called me and gave me also this solution with a single function which works too
function F_AUTOPILOT_callback(V_Electrical_Master_Battery, V_Avionics_Master_Switch, V_Autopilot_Master, V_Autopilot_FD )
.....
End
fs2020_variable_subscribe("ELECTRICAL MASTER BATTERY", "Boolean", "AVIONICS MASTER SWITCH", "Boolean", "AUTOPILOT MASTER", "Boolean", "AUTOPILOT FLIGHT DIRECTOR ACTIVE", "Boolean" , F_AUTOPILOT_callback)
Many thanks together for your help, i can continue
Best regards
Thierry
Re: FS2020_variable_subscribe
While both versions are correct, I personnally tend to avoid the inline definition functions (where the function callback is defined directly in the subscribe itself, like @Keith Baxter proposed) if I can, as I found that the code is too compact to be easily readable, especially after a while.
While the inline def is mandatory in the canvas_draw() function, for a simple function, this is not, and I doubt there is a real gain in execution time with having the in line def.
And the other drawback is that you cannot call an inline defined function externally (I mean apart from the subscribe function itself), which can be handy in the initialization phase.
Comme on dit, "c'est mon avis, et je le partage".
Jacques
While the inline def is mandatory in the canvas_draw() function, for a simple function, this is not, and I doubt there is a real gain in execution time with having the in line def.
And the other drawback is that you cannot call an inline defined function externally (I mean apart from the subscribe function itself), which can be handy in the initialization phase.
Comme on dit, "c'est mon avis, et je le partage".
Jacques
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: FS2020_variable_subscribe
Hi,JackZ wrote: ↑Sun Jan 16, 2022 10:53 am While both versions are correct, I personnally tend to avoid the inline definition functions (where the function callback is defined directly in the subscribe itself, like @Keith Baxter proposed) if I can, as I found that the code is too compact to be easily readable, especially after a while.
While the inline def is mandatory in the canvas_draw() function, for a simple function, this is not, and I doubt there is a real gain in execution time with having the in line def.
And the other drawback is that you cannot call an inline defined function externally (I mean apart from the subscribe function itself), which can be handy in the initialization phase.
Comme on dit, "c'est mon avis, et je le partage".
Jacques
Yes there are different views on inline functions. I do not agree that it is not easily readable. Takes time to change mindsets of aging peeps my cousin Jacques.
Take for example this switch. All the code to operate that switch is compact within the switch function. Nothing is scattered elsewhere within the script.
Just my coding style.
I know where to look should there be an issue with that switch /node.
Code: Select all
-- Add Alt1 switch
alt1_sw = switch_add(nil, nil,50, 50, 20, 60, function()
xpl_command("afm/sr/cmd/switches/alt1_Toggle")
xpl_dataref_subscribe("afm/sr/switches/alt1", "INT",function(alt)
switch_set_position(alt1_sw, alt)
end) end)
Keith
Last edited by Keith Baxter on Wed Jan 19, 2022 1:45 pm, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: FS2020_variable_subscribe
I'm not that big of an expert, but to me that looks like you're starting a new subscribe, every time you press that switch.
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: FS2020_variable_subscribe
Hi Ralph
Yes I did considered that. The AM console only reports 1 subscribe after each switch change. The viewer the same. So all seems good
Is it not that the subscribe is local and only within that function (call) and is persistent after multiple subscribes ???
Perhaps @Corjan can confirm if what you say is hot or cold.
I use this often without issues but do not want to advise questionable coding. After all, you guys are my teach.
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: FS2020_variable_subscribe
@Keith Baxter Caught yourself with your pants down on the inline def tree haha!
My YouTube Chanel on the A320 (Real SOPs by an Airline Pilot IRL):
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ
https://www.youtube.com/playlist?list=P ... 0Q6SBASRqJ