Sign in to follow this  
Rabso

Holding control for certain time in LUA

Recommended Posts

I am trying here to do small LUA scripts, after reading a lot about LUA, am still unable to do it.

 

The APU selector switch in 777 has off, on and start positions; in real life you should switch to Start for 5 seconds then release the switch which will go back to on. I am trying to simulate that.

 

I did the following code:

function APU_SEL_SWITCH_start_seq ()
	APU_SEL_SWITCH_start ()
	ipc.sleep (5000)
	APU_SEL_SWITCH_on ()
end

however, in above code there is no any hold for the Start position, the ipc.sleep is just to give a break of 5 seconds.

 

could any one help me with the hold code?

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

Hi Rabso

 

The ipc.sleep function is used a delay of n 1/1000s to allow actions to complete before continue with the next instruction. It does not cause the previous function to continue to operate. Are you asking before the start_seq is not on long enough to correctly start the engines or are you looking for accuracy of the simulation?

 

The easiest way to do this is to set the OnPress and OnRepeat to the 'start' function and the 'set' to the OnRelease. You would then hold the button pressed for the prerequisite 5s.

Share this post


Link to post
Share on other sites

yes am looking for accuracy of the simulation.

 

I am aware of the OnPress and OnRepeat then OnRelease, but this is only applicable for buttons where I am using switch in my Warthog throttle.

 

The idea is when I move the APU switch of my warthog to on, LUA will turn the 777 APU to start for 5 seconds then back to On

Share this post


Link to post
Share on other sites

Scotflieger, I have done the trick :Big Grin:

 

here is my code to share with all:

function APU_SEL_SWITCH_start_sequence()
    time1 = ipc.elapsedtime()

    while true do
        time2 = ipc.elapsedtime() - time1
	if time2 >= 2000 then
            break
        else
            APU_SEL_SWITCH_start ()
        end
    end

    APU_SEL_SWITCH_on ()
end

to explain,

- time1 will note the function start time

- entering a loop to keep the APU selector on Start position as long the time difference time between time2 and time1 less than 2 seconds.

- time2 will keep increasing as long the loop is going on.

- once difference time be more than 2 seconds, the loop will break, and then APU selector will go to On.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this