Running Multiple Lua Scripts

Started by garry23, June 13, 2016, 01:09:55 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

David (assuming you have the time)

Hopefully you can clarify a few questions in my mind.

If you have more than one script that is loaded at start up, how do they interact with each other?

Specifically, if both are, say, making use of, say, a keypress event handler, how do they decide who wins the event handling fight?

Also, if one script declares a global (sic) variable, is it global across all scripts or 'just' within the script that declares it.

Cheers

Garry

dmilligan

Quote from: garry23 on June 13, 2016, 01:09:55 PM
Specifically, if both are, say, making use of, say, a keypress event handler, how do they decide who wins the event handling fight?
Probably the one that got loaded first, so probably the one with the filename that comes first alphabetically. But it really depends on exactly how/when the scripts register and unregister those events.

Quote from: garry23 on June 13, 2016, 01:09:55 PM
Also, if one script declares a global (sic) variable, is it global across all scripts or 'just' within the script that declares it.
Each script get's its own global state, nothing is shared. More info on the first page of the docs

garry23

David

Thanks.

One thought I have had is that I have a single script that handles keypresses across all my scripts, ie one point of deconfliction. That is I just test what script is running and respond accordingly.

Do you think a reasonable approach?

Cheers

Garry

dmilligan

Quote
If you would like scripts to share a state, have only one of the scripts in the ML/SCRIPTS folder, and have it call the other scripts with dofile() or require()