Game Development Community

Would someone please tell me what I'm doing wrong here

by Jason Coggins · in Torque Game Builder · 07/01/2006 (7:58 pm) · 2 replies

TGB says there is a syntax error in the following code but I cannot find it.

function enemyShip::fireMissile(%this)
{
%this.enemyMissile = new t2dStaticSprite()
{
$fireSound = alxPlay(fireSound);
scenegraph = %this.scenegraph;
class = enemyMissile;
missileSpeed=%this.missileSpeed;
enemy = %this;
}
%this.enemyMissile.fire();
%this.schedule(getRandom(%this.minShoot, %this.maxShoot), "fireMissile");
}

Jason

#1
07/01/2006 (8:04 pm)
You are missing a semi-colon at the end of your t2dStaticSprite definition.

function enemyShip::fireMissile(%this)
{
%this.enemyMissile = new t2dStaticSprite()
{
$fireSound = alxPlay(fireSound);
scenegraph = %this.scenegraph;
class = enemyMissile;
missileSpeed=%this.missileSpeed;
enemy = %this;
};  // <------- NEED ME!
%this.enemyMissile.fire();
%this.schedule(getRandom(%this.minShoot, %this.maxShoot), "fireMissile");
}

All objects/datablocks that are created using the new method in script require that extra semicolon at the end of the definition.
#2
07/01/2006 (8:15 pm)
$firesound is a global scope variable and will not work in a datablock definition such as you are using here.

In fact, I'm not sure what you're doing with that line, but it won't work as it is anyway. Try removing the '$' from the beginning. Also, add a semicolon (;) after the first closing curly brace. Anyway, TGB seems to compile it that way for me, but I haven't tried testing it any further than getting it to exec

function enemyShip::fireMissile(%this)
{
%this.enemyMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = enemyMissile;
missileSpeed=%this.missileSpeed;
enemy = %this;
fireSound = alxPlay(fireSound);
};
%this.enemyMissile.fire();
%this.schedule(getRandom(%this.minShoot, %this.maxShoot), "fireMissile");
}