Page 1 of 1

Checking for an Event...

Posted: Fri Jun 12, 2020 9:27 am
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?


RE: Checking for an Event...

Posted: Fri Jun 12, 2020 2:03 pm
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.


RE: Checking for an Event...

Posted: Fri Jun 12, 2020 2:47 pm
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?

RE: Checking for an Event...

Posted: Fri Jun 12, 2020 4:47 pm
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.

RE: Checking for an Event...

Posted: Fri Jun 12, 2020 10:50 pm
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.

RE: Checking for an Event...

Posted: Fri Jun 12, 2020 10:54 pm
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.