Can class/superclass be set with a behavior?
by Dave Calabrese · in Torque Game Builder · 07/06/2008 (1:45 pm) · 4 replies
I'm working on putting together an enemy placement system for our game to make things easier on the level designer. The system works by having the designer place any object in the world, then assigning a 'Make Enemy' behavior, and choosing the enemy type from the list. The behavior then goes and assigns the proper enemy class and our overall enemy superclass with all the standardized AI code in it.
I've got it so that you can assigning the enemy classes and everything through the editor (using the setClassNamespace() method). What I'm getting caught up however is when the level goes to load. The object acts like it has no classes assigned to it, the 'onLevelLoaded()' method does not call, and no class-specific methods on that object will work, despite the object.dump(); showing the proper classes have been assigned.
I also receive this error:
Anyone have a hint on what's going on here?
-Dave Calabrese
Gaslight Studios
I've got it so that you can assigning the enemy classes and everything through the editor (using the setClassNamespace() method). What I'm getting caught up however is when the level goes to load. The object acts like it has no classes assigned to it, the 'onLevelLoaded()' method does not call, and no class-specific methods on that object will work, despite the object.dump(); showing the proper classes have been assigned.
I also receive this error:
Namespace::unlinkClass - cannot unlink namespace parent linkage for enemySuperclass for t2dStaticSprite. Error: cannot change namespace parent linkage of enemySuperclass from t2dStaticSprite to t2dAnimatedSprite. Error: cannot change namespace parent linkage of enemy_Doppleganger from enemySuperclass to t2dAnimatedSprite.
Anyone have a hint on what's going on here?
-Dave Calabrese
Gaslight Studios
About the author
Recent Threads
#2
But I think the way to go is to have the .t2d level file with your enemy objects actually have the class and superclass for your enemies already set up and saved correctly, in some way or another.
07/06/2008 (2:35 pm)
Actually setClassNamespace and setSuperclassNamespace do work, I have used them before for some simObjects that were created in C++ but needed a script namespace.But I think the way to go is to have the .t2d level file with your enemy objects actually have the class and superclass for your enemies already set up and saved correctly, in some way or another.
#3
Thanks!
-Dave Calabrese
Gaslight Studios
07/06/2008 (5:07 pm)
Okay... looks like the cleanest way is actually to create a different behavior for each enemy. So what I've done is create an 'enemyFunctions.cs' script file that contains a lot of standard behaviors, where I then just pass in the objects when needed from the main behaviors file. Overall, this looks like the easiest, cleanest and most friendly way to accomplish this.Thanks!
-Dave Calabrese
Gaslight Studios
#4
07/07/2008 (9:59 am)
Cool, that sounds like a good way to do it. One question, are they really "behaviors" in your enemyFunctions.cs? And if so, why? They sound to me like utility functions that take the object to operate on as a parameter, so why would that be a behavior and/or attached to an object?
Associate James Ford
Sickhead Games
So ... if you want to do this through a behavior you might want to have the behavior create a new object of the desired class/superclass onlevelloaded rather than trying to change the class of an existing object.
This could be done by having behavior field describing the class namespace of the enemy ( eg. EnemyTank ), and onLevelloaded calling %enemy = eval( %EnemyClass SPC "::create();" ); And defining a create function for each enemy type such that the correct staticsprite or animatedsprite is created and config datablock is assigned.
Alternatively, isn't this what config datablocks are usually for? You define a config datablock for each enemy type and then the level designer can place one easily by dragging over a static-sprite or whatever and assigning it the correct config datablock. If you also need a behavior for your enemy then apply both a config db and some behaviors. I think there is a way to have your config db(s) also add behaviors to your object (but I'm not sure). But doing two short steps instead of one isn't so bad.