Hello Team,
I seem to be having some trouble using the forum search correctly - but I am unable to locate this (assumedly) trivial piece of information.
I am trying to get the LUA-script to send an x-plane command WHILE a button is pressed.
while
function button_pitchtrim_up()
do
xpl_command("sim/flight_controls/pitch_trim_up")
print ("pitch trim up")
end
end
This piece of code is not working - but I am having a hard time figuring out the correct syntax. The LUA reference page does not give any specifics...
Could you please point me in the right direction?
Thanks in advance and cheers.
Benno
Do-While button is pressed.
-
- Posts: 5346
- Joined: Thu Jul 27, 2017 12:22 am
Re: Do-While button is pressed.
Hi Benno @BeRol
Perhaps with something like this as a first simple approach ?
Gilles
Perhaps with something like this as a first simple approach ?
Code: Select all
function button_pitchtrim_up()
xpl_command("sim/flight_controls/pitch_trim_up")
print ("pitch trim up")
end
btn_hw_pitch_up = hw_button_add("Pitch Trim UP",button_pitchtrim_up)
Re: Do-While button is pressed.
You need to BEGIN and END the command like this.
Code: Select all
function button_pitchtrim_up_press()
xpl_command("sim/flight_controls/pitch_trim_up", 1)
end
function button_pitchtrim_up_release()
xpl_command("sim/flight_controls/pitch_trim_up, 0)
end
btn_hw_pitch_up = hw_button_add("Pitch Trim UP",button_pitchtrim_up_press, button_pitchtrim_up_release)
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: Do-While button is pressed.
That did the trick!
Thank you very much.
I dare not ask why the LUA construct "Do-while-end" does not work in this case. Well - maybe some other time.
BTW - I really like the knobster!
Cheers
Benno
Thank you very much.
I dare not ask why the LUA construct "Do-while-end" does not work in this case. Well - maybe some other time.
BTW - I really like the knobster!
Cheers
Benno
Re: Do-While button is pressed.
Hi Benno,
The scripting done in Air Manager is event based.
This means that AM will call a function when something important happens. Things like new data from the simulator, a button being pressed, etc. etc. etc. You can immediately do your thing and let the function finish.
You should never use any for or while loops since that can lock up the script.
Corjan
The scripting done in Air Manager is event based.
This means that AM will call a function when something important happens. Things like new data from the simulator, a button being pressed, etc. etc. etc. You can immediately do your thing and let the function finish.
You should never use any for or while loops since that can lock up the script.
Corjan
Re: Do-While button is pressed.
I don’t agree with this. For and While loops can be used successfully for certain tasks as long as you have a defined way to complete the loop. They are very good for doing multiples of the same thing. Some code would be unnecessarily long and complex without them.
This for instance can be used to add all the tick marks for a compass. It has a definite and pre defined finish. It loops for 72 passes and then completes.
for i=1, 72 do
—add compass ticks
end
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: Do-While button is pressed.
For is okay, but while is a bit risky.
Re: Do-While button is pressed.
You are right, there are situations where it makes sense and is totally okay.Sling wrote: ↑Fri May 15, 2020 8:52 pmI don’t agree with this. For and While loops can be used successfully for certain tasks as long as you have a defined way to complete the loop. They are very good for doing multiples of the same thing. Some code would be unnecessarily long and complex without them.
This for instance can be used to add all the tick marks for a compass. It has a definite and pre defined finish. It loops for 72 passes and then completes.
for i=1, 72 do
—add compass ticks
end
Trying to say that you shouldn't make any loops that run indefinitely.
Corjan
Re: Do-While button is pressed.
100%. You have to be careful not to leave the completion of the loop open ended. Ralph is right, While can be a bit of a problem if the completion is not handled correctly.
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D