Checking for an Event...

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

Checking for an Event...

Post by jkgarner »

I need to silently check for the existence of an event by name.

If I call ScenEdit.GetEvent(), and the event exists, the code works fine, no error, the event is found.

If I call ScenEdit.GetEvent(), and it does not exist, Command throws up an error message to the user (not silent) AND the script stops executing.

If I wrap the ScenEdit.GetEvent() with pcall or xpcall to trap the error, the same thing happens. (not silent) AND the script stops executing.

So I tried ScenEdit_GetEvents() to iterate through the list manually...
but this returns an error: attempt to call global 'ScenEdit_GetEvents' (a nil value)

Perhaps I am missing something, but I still need to test for the existence of my event.

Any thoughts?

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

RE: Checking for an Event...

Post by KnightHawk75 »

I think the GetEvents() issue there is you're on Pro and it was a recent addition\re-addition.

Odd I don't see that same behavior in commerical release. ie
local a = ScenEdit_GetEvent('SomeEventDoesNotExist');
Doesn't generate a error - not when it 'actually' runs inside an event.
It does of course in the lua console though, which can throw one off.
If you see that when you run it in the lua console or via special action try wrapping it in a
Tool_EmulateNoConsole(true)
..your code here..
Tool_EmulateNoConsole(false)
Which will try to force suppressing the error and the result of the above in the console should be no error and a==nil.

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

RE: Checking for an Event...

Post by jkgarner »

Does Tool_EmulateNoConsole have an effect when I am running in an event (not the console)?

Specifically, is it safe to throw in the script and leave there when there is a chance the script will be run in an event?
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Checking for an Event...

Post by KnightHawk75 »

I think that flag gets set on it's own when running in an event (or isn't checked cause it already knows itself it's inherently running in an event), but I could be wrong, so setting it shouldn't have an effect either way if it's really running in an event. That's definitely a Michael question. It shouldn't hurt if it's included though, it's lost after a chunk is done in my experience, ie it's not a global flag it's just for that execution. If running outside an event when the chuck is done running it will revert back to false, I know it does for console and SA.
User avatar
michaelm75au
Posts: 12465
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Checking for an Event...

Post by michaelm75au »

Tool_EmulateNoConsole() makes the script run as if it was in the "background" (like a normal event in game).
If you include it in an event script but have it 'false', it may cause the event to stop on an error. However, leaving it in with it set to 'true' should have no impact.
Michael
User avatar
michaelm75au
Posts: 12465
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Checking for an Event...

Post by michaelm75au »

ORIGINAL: jkgarner

I need to silently check for the existence of an event by name.

If I call ScenEdit.GetEvent(), and the event exists, the code works fine, no error, the event is found.

If I call ScenEdit.GetEvent(), and it does not exist, Command throws up an error message to the user (not silent) AND the script stops executing.

If I wrap the ScenEdit.GetEvent() with pcall or xpcall to trap the error, the same thing happens. (not silent) AND the script stops executing.

So I tried ScenEdit_GetEvents() to iterate through the list manually...
but this returns an error: attempt to call global 'ScenEdit_GetEvents' (a nil value)

Perhaps I am missing something, but I still need to test for the existence of my event.

Any thoughts?

Is this in a console or an event?
If a console, it will give an error.
If in an event, it should return nothing/nil.
Michael
Post Reply

Return to “Lua Legion”