October 14, 20232 yr I am trying to figure out the best way to complete multiple actions in a script before the next action happens. There are variable lengths for how long each action takes depending on the switch position. For example in the Leonardo MD82 I cannot simply set the light switches for instruments and flood lights to an LVAR and have the brightness level I want. The MD82 requires you send a number to a specific LVAR and a mouse click or wheel scroll happens in the cockpit. What I do is read the light switch LVAR. That tells me the position, say it reads 20. I then know the number of clicks in which direction I need to set the lights to the position I want, let's say 10 is the correct brightness. I have the script do some math and the LVAR moves by 2 for each click, so I know I need 5 clicks to the left. I use iterate in the script and it works perfectly. However, I don't know how many clicks I will need each time I run the script. The problem is that there are about 10 light switches in the cockpit. I run the calculation and if statement for each switch. However, the switches start iterating on top of each other. This eventually floods the cockpit and some of the clicks get lost. Is it possible to have the script wait until the iterations are done before moving to the next script? I can use (WAIT:xxx) and guess the number of ms but it's dynamic how long each switch takes. I tried the loop function but that is very slow. See below for how I have it set up now. Each one on their own works great. However, they start to flood and work over the top of each other. 10·(L:CM1_panel_light_knob1,·Number)·-·2·div·sp0· l0·0·<=·if{·l0·-1·*·iterate{·8192·10·+·(>L:CM1_lateral_event,number)·(WAIT:250)·}next·}· els{·l0·iterate{·16384·10·+·(>L:CM1_lateral_event,number)·(WAIT:250)·}next·}· (WAIT:250)· 4·(L:CM1_panel_flood_knob2,·number)·-·2·div·sp1· l1·0·<=·if{·l1·-1·*·iterate{·8192·13·+·(>L:CM1_lateral_event,number)·(WAIT:200)·}next·}· els{·l1·iterate{·16384·13·+·(>L:CM1_lateral_event,number)·(WAIT:200)·}next·}· (WAIT:250)· 2·(L:CM1_panel_flood_knob1,·number)·-·2·div·sp2· l2·0·<=·if{·l2·-1·*·iterate{·8192·12·+·(>L:CM1_lateral_event,number)·(WAIT:200)·}next·}· els{·l2·iterate{·16384·12·+·(>L:CM1_lateral_event,number)·(WAIT:200)·}next·}· (WAIT:250)· 10·(L:center_panel_light_knob1,·number)·-·2·div·sp3· l3·0·<=·if{·l3·-1·*·iterate{·8192·34·+·(>L:radio_event,number)·(WAIT:200)·}next·}· els{·l3·iterate{·16384·34·+·(>L:radio_event,number)·(WAIT:200)·}next·}· (WAIT:250)· 6·(L:center_panel_light_knob2,·number)·-·2·div·sp4· l4·0·<=·if{·l4·-1·*·iterate{·8192·35·+·(>L:radio_event,number)·(WAIT:200)·}next·}· els{·l4·iterate{·16384·35·+·(>L:radio_event,number)·(WAIT:200)·}next·}· (WAIT:250)· 4·(L:center_flood_light_knob1,·number)·-·2·div·sp5· l5·0·<=·if{·l5·-1·*·iterate{·8192·37·+·(>L:radio_event,number)·(WAIT:200)·}next·}· els{·l5·iterate{·16384·37·+·(>L:radio_event,number)·(WAIT:200)·}next·}· (WAIT:250)· 90·(L:fgcp_light_knob1,·number)·-·2·div·sp6· l6·0·<=·if{·l6·-1·*·iterate{·16384·20·+·(>L:fgcp_event,number)·(WAIT:200)·}next·}· els{·l6·iterate{·8192·20·+·(>L:fgcp_event,number)·(WAIT:200)·}next·}· (WAIT:250)· 40·(L:fgcp_light_knob2,·number)·-·2·div·sp7· l7·0·<=·if{·l7·-1·*·iterate{·16384·21·+·(>L:fgcp_event,number)·(WAIT:200)·}next·}· els{·l7·iterate{·8192·21·+·(>L:fgcp_event,number)·(WAIT:200)·}next·}· (WAIT:250)· 10·(L:ovhd_panel_light_knob1,·number)·-·2·div·sp8· l8·0·<=·if{·l8·-1·*·iterate{·8192·78·+·(>L:overhead_event,number)·(WAIT:200)·}next·}· els{·l8·iterate{·16384·78·+·(>L:overhead_event,number)·(WAIT:200)·}next·}· (WAIT:250)· 4·(L:ovhd_flood_light_knob1,·number)·-·2·div·sp9· l9·0·<=·if{·l9·-1·*·iterate{·8192·79·+·(>L:overhead_event,number)·(WAIT:200)·}next·}· els{·l9·iterate{·16384·79·+·(>L:overhead_event,number)·(WAIT:200)·}next·}· (WAIT:250)· (L:ovhd_pull_dim_switch1,·number)·0·==·if{·536870912·66·+·(>L:overhead_event,number)·}
October 14, 20232 yr Commercial Member That is one large script... I'm not sure that I understand why you have to handle all 10 switches at the same time, in the same script? I would probably do this in a script file which is easier to read. Script files can be cached, so there isn't a disk access happening every time you call it. If it has to be synchronous, you can use labels and GOTO, so the logic can only proceed once you jump out of the loop. :loop1some rpn code condition if{ (GOTO:loop2) } (GOTO:loop1) :loop2 more rpn code etc. In this case you don't have to pre-calculate the number of iterations, you just run the loop until the goal has been reached. All that being said - are you quite sure about the LVars option? Those look like animation controls. I thought that Leonardo relies on custom events? C:\Users\...\Documents\Maddog X Files\Docs\List of Commands.pdf KEY CNT PANEL LTS SET 69939 0x11133 AFAIK translates to n (>K:#69939) No idea what value n is supposed to be, the spec doesn't say. Edited October 14, 20232 yr by Lorby_SI LORBY-SI
October 18, 20232 yr Author Yes, it is a little long, but I like to use scripts to automate some of the simple checklist items. When I land, or arrive at the gate, or before taxi, I like to focus on the big ticket items and have the little things automatically done for me. In general it works even if that's not what the script function is fully intended to do. Cockpit lights are a big one especially in VR. Most planes have quite a few light switches, so I use a script to dial in the exact settings I like. Simple push of a button and I have perfect cockpit lighting. Additionally, is there a way to suppress an axis based on a variable? This would be great for autothrottle in planes like the Maddog. I would love the ability to have the throttle axis only working when the autothrottle is turned off.
Archived
This topic is now archived and is closed to further replies.