Jump to content
The simFlight Network Forums

How to Keep a Lua Script from Terminating?


ark1320

Recommended Posts

What is a good way to keep a Lua script from terminating?  One way I found is to put a "dummy" (empty) do while true at the end of the script like this:

WIndow Script code here

do while true

end

In the particular case I have, the script above simply opens a window for display that I want another script to be able to use. So I don't want the window to close. I pass the window's handle to the other script, and this seems to work OK. The other script is called frequently as data is entered, and if I put the window definition code in that script, then each time the script runs the window flashes. If the window stays open there is no flashing.
I just wonder if there is a better way to keep the window script from terminating then using the empty do while true?

Thanks,

Al

Link to comment
Share on other sites

You can do that but I would not recommend it - a script should run and exit when finished. There is no other way to keep a lua thread running as this should not be necessary.

Create the window in the other script and try to eliminate whatever is causing the "flashing". 

Link to comment
Share on other sites

A flash happens when a window is opened, and since the "other" script is called numerous times, the window is opened and flashes each time.

I don't think there is a good solution for this kind of situation.

Thanks,

Al

Link to comment
Share on other sites

If you want the window to be always open, then you should have one script that creates the window and then waits for events to update the windows contents. The events could be anything - an offset change, a flag change, a button or key press/release, an event, etc. You do not need two scripts, or to create the window each time.

Link to comment
Share on other sites

10 hours ago, John Dowson said:

If you want the window to be always open, then you should have one script that creates the window and then waits for events to update the windows contents. The events could be anything - an offset change, a flag change, a button or key press/release, an event, etc. You do not need two scripts, or to create the window each time.

I understand John, and in fact have a number of scripts that do just that. This was a particular situation where as an experiment I did not want to use an event driven script.

Thanks,

Al

Link to comment
Share on other sites

13 hours ago, ark1320 said:

This was a particular situation where as an experiment I did not want to use an event driven script.

You could also register for an event but do nothing in the event handling function- just registering for the event will keep your script running/window open. You could even use a timer event if you wanted to close the window after a number of seconds/minutes. The lua script that updates the window could run the lua that creates the window if the window isn't available/created yet, or use the handle if the window was available.

If using an endless loop to keep the window open, maybe add a sleep call in the loop body.

John 

Link to comment
Share on other sites

6 hours ago, John Dowson said:

You could also register for an event but do nothing in the event handling function- just registering for the event will keep your script running/window open. You could even use a timer event if you wanted to close the window after a number of seconds/minutes. The lua script that updates the window could run the lua that creates the window if the window isn't available/created yet, or use the handle if the window was available.

If using an endless loop to keep the window open, maybe add a sleep call in the loop body.

John 

John -- interesting ideas, thanks very much!

Al

Link to comment
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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.