Lua Editor Hooks: How to prevent endless loop?

I wanna modify the fades of any moved region automatically (Lua Editor Hook):

When using LuaSignal.RegionPropertyChanged to detect if any region is moved (or trimmed), and then automatically modifying the region’s properties, leads to an endless loop, because the Lua signal is of course fired again by the intentional modification…

How would you prevent this?

(At best - depending on what you want to do -, the script is called twice, because the second time the intentional modifications already happened and the regions don’t get altered anymore (and therefore no new Lua signal is fired)…)

There are two types of modifications: user made and automatic and your program needs a capability to distinguish between the two.

You could use a timestamp (if available) to ignore modifications made by the script for a short period of time after the modification (say 200 ms). You could have a list of regions that the script modified just now and then ignore those regions on the next run loop and delete this list at the end of it. Somehow you need to store info about regions the script modified and make it ignore those on the next run and then empty the list.

These are just generic programming suggestions, I’m not a lua user at the moment.

Thanks for your answer!

You can do that even with global variables which seem to stay valid between script runs! So that could be relatively easy…

But I thought there might be a simpler solution tough than keeping track by hand…?

If you have access to system clock and region modification timestamps, then you could store the time when your script starts and stops and on the next run ignore regions modified between those.