Sorry, we don't support your browser.  Install a modern browser
This post is closed.

onObjectLeaveScriptingZone is triggered when going to main menu#929

What happens:
The ‘onObjectLeaveScriptingZone’ function is triggered when a player (the host) leaves the game and enters the main menu.
It seems to trigger for each object inside of a scripting zone when the game ended.

What should happen:
The ‘onObjectLeaveScriptingZone’ function is not triggered when entering the main menu.

Why is this a bug:
Object states are funky when the game no longer exists (when the player enters the main menu). This means that you often get ‘Object reference not set to an instance of an object’ errors when entering the main menu. When multiple objects listen to the scripting event, and a lot of objects are present in scripting zones on game end, then it is quite possible to reach up to 300 errors. This often causes TTS to become really slow as it seems to handle all the errors one by one.

How to reproduce:
Create a Go game. Create a scripting zone (on the board, or beside, doesn’t matter). Place multiple Go tokens in the scripting zone. Save the game. Add the following code

function onObjectLeaveScriptingZone(zone, leave_object)
    print('object leave scripting zone')
end

Save the script, save the game. Load the game (probably not required, but just to be sure). Now go to ‘Menu’ -> ‘Main Menu’ -> ‘Yes’. Look in your chat for multiple log messages (matching the amount of objects in scripting zones).

Possible workaround (for modders currently experiencing the issue):
Check if the game is still active:

function onObjectLeaveScriptingZone(zone, leave_object)
    if(Info == nil or Info.name == nil) then return end -- check if game state is valid
    print('object leave scripting zone')
end
3 years ago

Now this is how you file a bug report.

3 years ago
1
Changed the status to
In Progress
3 years ago
1

Tried your “Info==nil” test, but I’m still getting the errors and long exits. It kind of makes sense. If the script has time enough to register the object exiting the scripting zone, then it probably hasn’t removed the Info data yet. I was trying a Wait.Frame of 2, then testing if the leaving object still existed, but it caused some issues deeper in my script (not a TTS fault, just the way I programmed things). Looking forward to it fixed in the next patch.

3 years ago
Changed the status to
Completed
2 years ago

Can confirm; its working like a charm again. Thanks for the patch!

2 years ago