Game Development Community

Cant unload module

by Mehmet Emre Yorulmaz · in Torque 2D Beginner · 06/01/2015 (11:47 am) · 3 replies

Hello again,i seem to be having trouble with unloading modules.
I used to the gui system to make a pause menu which can be accessed using the escape key.
My problem is with the button on that pause menu which should let the user go back to the main menu by unloading its current module(level1 2 etc), and pushing the main menu dialog without loading another module since the main menu module is never unloaded.

function Mainmenubuttonp::onClick(%this){
Canvas.popDialog(PauseDialog);
Canvas.popdialog(Hud);
ModuleDatabase.unloadGroup("gsg");
Canvas.pushDialog(MenuDialog);
}

This is the "onclick" function for the main menu button whenever its executed i get this error:
"object is being unregistered whilst performing a script callback".I have tried using the debug build of Torque 2d
which asks me if i want to use the debugger but whenever i click "yes" it seems to crash...
I also tried to enable the echo functions for the module and asset info to see if valuable info would come up on the console but sadly it did not.
The weird part is when i copy the body of this function into the console and execute it there,the game does not crash,and the only difference between the console outputs of the first and second situation(button execution and console execution) is something along the lines of "unloading complete".
How can i fix this error?

#1
06/01/2015 (6:39 pm)
ModuleDatabase.schedule(64, unloadGroup, "gsg");
This should ask the ModuleDatabase to call unloadGroup("gsg") in 64 ms (or about two ticks) and avoid it happening during the onClick() callback.

Should work...
#2
06/02/2015 (12:23 am)
It does work,thanks again.
So i was able unload through the console because there was no onclick() callback...
#3
06/02/2015 (5:48 am)
Yeah. Try to avoid doing any deleting/removing of pretty much anything during a callback. Push/Pop is fine - all that is doing is showing/hiding stuff.