Game Development Community

First timer (shooter tut)

by Joseph *Nailo* Rick · in Torque Game Builder · 04/26/2007 (10:16 pm) · 8 replies

Well I've started in on the tuts, and after a few fumbles with the scripting I've gotten things underway rather well. I have, however, come across an issue I don't quite understand.

I'm trying to get the missle code to work, I've gotten all the script in where I am supposed to, but I cannot seem to fire the missles. When I look at the ~ screen I get an error "Unknown Command Fire". Can someone explain what I may have done wrong? (I have followed the tut exactly copy/paste with the script).

#1
04/27/2007 (7:12 am)
Sounds like the function that handles your firing isn't bound to the object trying to use it -- either a typo, or a few missed lines of code ... hard to say without seeing the code.
#2
04/27/2007 (8:45 am)
Well, as I stated it's a copy/paste of the code given from the tutorial:

player.cs:

[b]***bindings***[/b]

function playerShip::onLevelLoaded(%this, %scenegraph)
{
  //set the player's ship name to the instance
  $pShip = %this;
  
   moveMap.bindCmd(keyboard, "w", "pShipUp();", "pShipUpStop();");
   moveMap.bindCmd(keyboard, "s", "pShipDown();", "pShipDownStop();");
   moveMap.bindCmd(keyboard, "a", "pShipLeft();", "pShipLeftStop();");
   moveMap.bindCmd(keyboard, "d", "pShipRight();", "pShipRightStop();");
   moveMap.bindCmd(keyboard, "space", "$pShip.createMissile();", "");

}

[b]***function from binding (placed as last piece of script)***[/b]

function playerShip::createMissile(%this)
{
   %this.playerMissile = new t2dStaticSprite()
    {
        scenegraph = %this.scenegraph;
        class = playerMissile;
        missileSpeed=%this.missileSpeed;
        player = %this;
    };
       %this.playerMissile.fire();
}

playerMissle.cs

function playerMissile::fire(%this)
{
    %this.setWorldLimit( kill, "-136.000 -98.000 136.000 95" );
    %this.setLinearVelocityX(%this.missileSpeed);
    %this.setPosition(%this.player.getPosition());
    %this.setImageMap(playerMissileImageMap);
    %this.setSize(50, 20);
    %this.setCollisionActive( true, true );
    %this.setCollisionPhysics(false, false);
    %this.setCollisionCallback(true);
}

function playerMissile::onCollision( %srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts )
{
    if(%dstObj.class $= "enemyShip")
    {
       %srcObj.explode();	
       %dstObj.explode();
    }
}

function playerMissile::explode(%this)
{
    %this.safeDelete();
}

main.cs

function initializeProject()
{
   // Load up the in game gui.
   exec("~/gui/mainScreen.gui");
   
   // Exec game scripts.
   exec("./gameScripts/game.cs");
   exec("./gameScripts/player.cs");
   exec("./gameScripts/enemy.cs");
   exec("./gameScripts/playerMissile.cs");
#3
04/27/2007 (8:53 am)
Joseph ... ok ... now put some "echo" statements in your code, like so:

function playerMissile::fire(%this)
{
    [b]echo("playerMissle::fire(" @ %this @ ");");[/b]
    %this.setWorldLimit( kill, "-136.000 -98.000 136.000 95" );
    %this.setLinearVelocityX(%this.missileSpeed);
    %this.setPosition(%this.player.getPosition());
    %this.setImageMap(playerMissileImageMap);
    %this.setSize(50, 20);
    %this.setCollisionActive( true, true );
    %this.setCollisionPhysics(false, false);
    %this.setCollisionCallback(true);
}

This will let you know if the function is even being called, and you can check for the print out in the '~' screen (the console).

You can also use warn() and error() if you want to change up the colors a bit ... warn is a light grey, and error is a red ... they have no effect on how things work ... they just automatically color things for you ... I usually use error in the first function call, and warn in the preceeding calls ... I reserve echo for regular messages ... ;)

This will help you track down whats missing ... it might also help to know whether or not your movement key bindings work ... I assume they do, since you didn't say they don't ...

I'm also not quite sure why the tutorial has you calling pShipUp and such ... but $pShip.createMissle for firing ... seems an odd way to do things ... this may also be causing a problem, though not likely ...
#4
04/27/2007 (9:10 am)
I placed the echo in the script and re-read all of the info from the '~' screen

First, don't ever try to read script while half asleep lol...

The problem was with a spelling "error". My playerMissile.cs file was misspelled.

Thanks for the pionters: the warn() and error() will help out a lot in the future.
#5
04/27/2007 (9:25 am)
Np -- good debugging skills are always extremely useful ... even the best coders "rm -rf /" sometimes ;)
#6
07/09/2007 (9:36 pm)
Yay! i just completed the tutorial (first one too) and I retyped everything as I went. My question is on the end product.

While playing in the test mode, when the player is hit the ship explodes and in two seconds it respawns. My question is.. When the player is hit, is the ship supposed to disappear or does it remain on screen until the respawn?

I appreciate any input, thanks!
#7
07/09/2007 (9:41 pm)
Yay! i just completed the tutorial (first one too) and I retyped everything as I went. My question is on the end product.

While playing in the test mode, when the player is hit the ship explodes and in two seconds it respawns. My question is.. When the player is hit, is the ship supposed to disappear or does it remain on screen until the respawn?

I appreciate any input, thanks!
#8
07/11/2007 (11:08 am)
The ship its supposed to dissapear (maybe wit an explosion effect or whatever)... if its remaining on screen, check that the playerShip:explsion (or whatever its called) function its setting the playership to invisible correctly... or maybe deleting it.