Stupid Question.. disabling behavior in editor
by Simon Jensen · in Torque Game Builder · 12/16/2011 (1:54 pm) · 2 replies
Ok, so this is making me crazy.. but probably my brain is missing something.
How do I tell my behaviors to not start doing stuff when the editor is running?
My Problem:
I have a sprite in the game that has a behavior called monsterSpawnerBehavor added to it.
The behavior works fine by doing something like So:
The problem is that when I load up my level in the editor instead of working through script the behavior starts spawning monsters in the editor. And spawned monsters are relying on all sorts of other stuff that isn't on the board until the level is actually played, so my error log fills up to 45mb or so before TGB just crashes.
How do I tell my behaviors to not start doing stuff when the editor is running?
My Problem:
I have a sprite in the game that has a behavior called monsterSpawnerBehavor added to it.
The behavior works fine by doing something like So:
function MonsterSpawnerBehavior::onBehaviorAdd(%this){
// Add this to the spawner simSet so we can do triggers and broadcasts
monsterSpawnersSet.add(%this);
%this.monsterCount = 0;
if (%this.autoStart){
%this.bActive = true;
%this.schedule(%this.getWait(),"spawnNewMonster");
}else{
%this.bActive = false;
}
}The problem is that when I load up my level in the editor instead of working through script the behavior starts spawning monsters in the editor. And spawned monsters are relying on all sorts of other stuff that isn't on the board until the level is actually played, so my error log fills up to 45mb or so before TGB just crashes.
#2
I think I'll make my LevelManager class send out a notification to the spawners in the monsterSpawnerSet that the level has started once the game starts.
Just as soon as I get 1.7.6 to recompile with my tweaks.
12/17/2011 (8:10 am)
Oh doh.. yeah.. that makes sense. I think I'll make my LevelManager class send out a notification to the spawners in the monsterSpawnerSet that the level has started once the game starts.
Just as soon as I get 1.7.6 to recompile with my tweaks.
Torque Owner Rpahut
onAddToScene() - called for sceneObject added to the scene; not called for behaviors directly as they are not sceneObjects, but can be passed in from behavior's owner as I guess.
onBehaviorAdd() - called for behavior added to its owner
onBehaviorAdd would usually contain additional initialization related specifically to behavior being added to the object. You probably don't want your monsters to spawn until spawner object itself is added to the scene, so that code of yours should go under onAddToScene(). This addToScene callback will also be suppressed when loading level in the editor.
There was a discussion recently about onAddToScene not called for behaviors at all, so you may want to turn your spawner behavior into a class, and maybe have a utility behavior just to expose spawner controls and settings in the editor.