Spawning on Score.
by Daniel Novatnak · in Torque Game Builder · 09/13/2006 (9:14 pm) · 6 replies
Im making a 2d shooter and i am trying to spawn a boss once a certain score is reached... i've declared a global variable for the score but for some reason i cant seem to call the bossShip.spawn() function ... any advice?
#2
09/14/2006 (9:18 am)
Yea it's UCF. I am a Digital Media Major. and this class is Game Design tought by Dr. Vick. thanks for the help i'll let you know if it helps.
#3
function playerShip::spawnNewBoss()
{
%this.bossShip= new t2dStaticSprite();
%this.bossShip.spawn();
}
we keep getting an error where we are unable to find the object
the name of my boss ship is bigShip and the class is bossShip
any help?
oh and Vick says hey..
09/14/2006 (9:55 am)
Hey Tom, we got it to work up until a certain point and me and Vick are stumpedfunction playerShip::spawnNewBoss()
{
%this.bossShip= new t2dStaticSprite();
%this.bossShip.spawn();
}
we keep getting an error where we are unable to find the object
the name of my boss ship is bigShip and the class is bossShip
any help?
oh and Vick says hey..
#4
function playerShip::spawnNewBoss()
{
%this.bossShip= new t2dStaticSprite();
%this.bossShip.spawn();
}
we keep getting an error where we are unable to find the object
the name of my boss ship is bigShip and the class is bossShip
any help?
oh and Vick says hey..
09/14/2006 (10:10 am)
Hey Tom, we got it to work up until a certain point and me and Vick are stumpedfunction playerShip::spawnNewBoss()
{
%this.bossShip= new t2dStaticSprite();
%this.bossShip.spawn();
}
we keep getting an error where we are unable to find the object
the name of my boss ship is bigShip and the class is bossShip
any help?
oh and Vick says hey..
#5
function playerShip::spawnNewBoss()
{
%this.bossShip= new t2dStaticSprite();
%this.bossShip.spawn();
}
we keep getting an error where we are unable to find the object
the name of my boss ship is bigShip and the class is bossShip
any help?
oh and Vick says hey..
edit - the boss spawn works fine now thanks
09/14/2006 (11:08 am)
Hey Tom, we got it to work up until a certain point and me and Vick are stumpedfunction playerShip::spawnNewBoss()
{
%this.bossShip= new t2dStaticSprite();
%this.bossShip.spawn();
}
we keep getting an error where we are unable to find the object
the name of my boss ship is bigShip and the class is bossShip
any help?
oh and Vick says hey..
edit - the boss spawn works fine now thanks
#6
If you're going to be dynamically creating objects, it's best to have datablocks set up for them that define their imageMap, collision poly, size, class, etc.
Let me know how this works out for ya.
09/14/2006 (11:21 am)
Hah! Good ol' Dr.Vick. Well that's cool. Except for the lack of participation when I took it, I loved that class. Death Race 2000! Anyway... back to your thing:If you're going to be dynamically creating objects, it's best to have datablocks set up for them that define their imageMap, collision poly, size, class, etc.
// here's a datablock example
new t2dSceneObjectDatablock( BossShipDatablock )
{
class = bossClass;
imagemap = bossImageMap;
size = "10 10";
}; // note the semicolon here
// here's how you use it
function playerShip::spawnNewBoss( %this )
{
%this.bossShip = new t2dStaticSprite()
{
scenegraph = %this.getSceneGraph();
config = BossShipDatablock;
};
}
// and on the bossShip namespace...
function bossShip::onAdd( %this )
{
echo( "hey, i'm a boss that just got added." );
}Let me know how this works out for ya.
Torque Owner Thomas Buscaglia
Your problem might also be in your namespace usage. If there are no objects linked to the bossShip namespace at the time of the call (meaning that they are specifically named bossShip) you would get the error "unable to find object 'bossShip' when trying to blah blah..." in the console if you tried to call bossShip.spawn() in that syntax.
Here's an example:
function YourPlayerClass::onLevelLoaded( %this, %scenegraph ) { ... // turn on the onTimer callback and set it to call every 5 seconds (5000 ms) %this.setTimerOn( 5000 ); // initialize the bossSpawnScore field so we spawn a boss once we hit 10000 points %this.bossSpawnScore = 10000; ... } function YourPlayerClass::onTimer( %this ) { if( %this.yourPlayerScore >= %this.bossSpawnScore ) { YourBossClass::spawnNewBoss(); %this.setTimerOff(); } } function YourBossClass::spawnNewBoss() { ... // blah blah make a new boss }I'm not sure if this answered your question. If not, post back with more specific info.
By the way, is that the University of Central Florida UCF? I ask cause I used to go there and I'm interested to know what class/major/spec you're taking.
Edit: Typo...