Managing script to script conflicts

Started by garry23, April 01, 2019, 05:53:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

@a1ex

I'm looking to refactor my scripts so they work better together.

The issue I usually face is that script A looks to use a key 1, but so does script B.

I'm therefore looking to somehow use my cycler script as a master control script, ie to manage event.keypress and event.shoot_task, ie to deconflict scripts.

What I don't fully understand is how the keypress event is handled, ie does it pass through each script in turn?

When you have a spare moment, I hope you can throw some education my way  ;)

Cheers

Garry

a1ex

I think I've answered it before, but... here it goes.

https://builds.magiclantern.fm/lua_api/modules/event.html#keypress

The Lua module passes the key press event to all scripts that want to use it. Each script may decide to use the event, or not. This decision is in the return value - if you return false, that means the key event is not going to be forwarded to other scripts, modules, or to Canon firmware.

So, if you want to take over the MENU key, and to prevent the user from entering Canon menu, you will need to return "false" when receiving this key event.

If more than one script registers a keypress event, the first one (alphabetically, from file name) will receive it first. Same for modules. Not the best idea, but at least slightly more predictable than random.

garry23

@a1ex

Thanks, that's what I thought, however, I'm 'confused' a little.

If I have two scripts loaded, a.lua and b.lua, then a.lau script deals with the key first. 

If a.lua returns true for that key, then b.lua doesn't see the key, correct? In other words it has been 'consumed'.

But what if a.lua returns false, does that mean b.lua gets access to managing the key?

And once all scripts have been addressed, then and only then the key, if still true, is handled by the Canon side.

Have I got it right?

Cheers

Garry

a1ex

If a.lua returns false for that key, then b.lua is not going to see it, i.e. "return false" means it has been 'consumed'.

If all the handlers (from scripts, modules, ML core) return true for that key (i.e. "not consumed"), only in this case that key is going to reach Canon firmware.

garry23

Got it!

Many, many thanks.

Cheers

Garry