Lua Script Events Aren't Called Across Scripts

I assume Script Events are intended to be called across multiple scripts. I get a null callback error when I attempt calling a script event defined in one script from a different script. I know the script event is properly set up because it works fine when called from the script it’s defined in. I only get this error when calling it from an outside script. Any idea why this should be happening or is this the expected behavior?

I did some more testing of script events and I figured out the issue. I also found a number of bugs that exist for Lua Script Events.

For anyone who’s having the same issue, the problem was that I was declaring the script event subscriber as a local variable in OnActivate(). The table with function definitions that subscribes to the script event shouldn’t be declared using the “local” keyword, it should just be declared with a given name. After making this change, I was able to get global script events working in Lua.

However, after doing this, I still couldn’t get addressable script events working in Lua. Attempting to call an addressable script event from an outside script results in the engine crashing and closing out instantly. I also noticed that global broadcast script events with functions with more than one parameter failed to carry over any parameters aside from the first one. So my findings are as follows:

  • The table that subscribes to script events cannot be declared using local keyword
  • Attempting to call an addressable script event from a separate script results in the engine crashing
  • Only non-addressable broadcast events can be called from an outside script
  • Calling a non-addressable broadcast event with multiple parameters only carries over the first parameter

These gotcha bugs with this engine are really getting annoying.

2 Likes

Just found another bug. Creating a script event in Lua and setting a method return type as EntityId() also inexplicably crashes the engine.

1 Like