Finding a trigger (check for existence)

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

Finding a trigger (check for existence)

Post by jkgarner »

I am building a simple unit AI function in Lua...
Basically I am writing a function to have it randomly do a few things. I want to call the function against a unit and have the function randomly schedule the next trigger/event to call the function again, until such a time as I turn the behaviour off.

I understand math.random and creating triggers and events.

What I do not understand is how to use the limited Trigger functions (like ScenEdit_SetTrigger, or ScenEdit_SetEventTrigger) to
check for the existence of a trigger. It is possible that I need to use ScenEdit_GetEvent for this.

Any thoughts? (recommendations?)



KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Finding a trigger (check for existence)

Post by KnightHawk75 »

If you know the event name and will be reusing it I posted a snippet a week or two ago that might be helpful in highlighting how to get the associated trigger drop it and replace it with a new one (that gets a fresh fired flag that isn't set yet). It uses both functions.

fb.asp?m=4822744 [post #4]


Edit: As for literal test for existence I believe if you SetTrigger() and it bombs due to invalid trigger or otherwise etc, the return value should be nil or at least type ~= 'table' vs. a table when it succeeds.
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Finding a trigger (check for existence)

Post by jkgarner »

Thanks for the quick response...

I've looked over it, good stuff, as always. Useful stuff, but is this a heavy hammer (delete and recreate)?

Of, course it may be necessary if you're using a time trigger (trigger of type time), what of other types? Is this approach still needed?

This all begs the question in my mind: what are the trigger types? Yet another thing not listed in the documentation.[:o]
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Finding a trigger (check for existence)

Post by KnightHawk75 »

When it comes to specific-time triggers, if you don't remove the old one, and instead just update the time, it will never ever fire again if it's already triggered, hence the heavy hammer. When it comes to nearly every other type (that comes to mind anyway), there is no need for the delete, just use mode 'update', which I think 9:10 times is the default mode anyway so may not even need to specify it.

Haha.. yeah if you want to learn the text type code\right properties for each type, create 1 of everything assign them to an event, and then dump the triggers table dumping every sub-table and look them over. :)

Post Reply

Return to “Lua Legion”