Game Development Community

Shooter Tutorial

by Paul Jackson · in Torque Game Builder · 05/18/2006 (10:58 pm) · 33 replies

I am working on the shooter demo from the TDN basic tutorial. I am having trouble getting the player ship to shoot missiles. I have put in all the script it needs and have checked ten times to make sure there are no syntax errors but there are none. I have no idea what to do i have added some code in hopes someone my catch what i am doing wrong. I am using a mac with OS X and using beta 2 TGB.


function playerShip::onLevelLoaded(%this, %scenegraph)
{
$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();", "");
}
function pShipUp()
{
$pShip.moveUp = true;
$pShip.updateMovement();
}

function pShipDown()
{
$pShip.moveDown = true;
$pShip.updateMovement();
}

function pShipLeft()
{
$pShip.moveLeft = true;
$pShip.updateMovement();
}

function pShipRight()
{
$pShip.moveRight = true;
$pShip.updateMovement();
}

function pShipLeftStop()
{
$pShip.moveLeft = false;
$pShip.updateMovement();
}

function pShipRightStop()
{
$pShip.moveRight = false;
$pShip.updateMovement();
}

function pShipUpStop()
{
$pShip.moveUp = false;
$pShip.updateMovement();
}

function pShipDownStop()
{
$pShip.moveDown = false;
$pShip.updateMovement();
}
function playerShip::updateMovement(%this)
{
if(%this.moveLeft)
{
%this.setLinearVelocityX( -$pShip.hSpeed );
}

if(%this.moveRight)
{
%this.setLinearVelocityX( $pShip.hSpeed );
}
if(%this.moveUp)
{
%this.setLinearVelocityY( -$pShip.vSpeed );
}
if(%this.moveDown)
{
%this.setLinearVelocityY( $pShip.vSpeed );
}
if(!%this.moveLeft && !%this.moveRight)
{
%this.setLinearVelocityX( 0 );
}
if(!%this.moveUp && !%this.moveDown)
{
%this.setLinearVelocityY( 0 );
}
}
function playerShip::createMissile(%this)
{
%this.playerMissile = new t2dStaticSprite()
{
scenegraph = %this.scenegraph;
class = playerMissile;
missileSpeed=%this.missileSpeed;
player = %this;
};
%this.playerMissile.fire();
}



and this is the playermissile.cs

function playerMissile::fire(%this)
{
%this.setWorldLimit( kill, "-55.000 -420.000 600.000 40" );
%this.setLinearVelocityX(%this.missileSpeed);
%this.setPosition(%this.player.getPosition());
%this.setImageMap(playerMissileImageMap);
%this.setSize(22, 10);
%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();
}
Page «Previous 1 2
#1
05/18/2006 (11:11 pm)
Is that the code from the updated (latest) example, with fields added to Imagemaps in the level editor?

I know the older example worked with Beta 2 (I followed that one myself), but the updated one that has a lot of functionality done in the level editor may only work on Beta 3.

Just a guess on my behalf though, I haven't tried the new tutorial. Another possible point of failure is the fields for the Imagemaps, there are several for the player ship, including missile speed I believe
#2
05/18/2006 (11:15 pm)
It is the lastest update. Man i can't wait for beta 3 to be on the mac
#3
05/18/2006 (11:18 pm)
Actually, I am probably being hasty, I glanced at the tutorial and there are a few other things it could be.

Have you made sure you added:

exec("./gameScripts/playerMissile.cs");

Under the other EXEC's ?

And what does the console.log say? (or your debugger if you are using one?) that may be a lot more helpful than I've been :)
#4
05/18/2006 (11:22 pm)
Yeah i have that in the main
#5
05/18/2006 (11:32 pm)
What about console.log? No errors in there?
#6
05/18/2006 (11:47 pm)
I really don't understand what the console log is telling me i have tried to figure it out but i don't get it.
#7
05/18/2006 (11:53 pm)
Hurm, ok. I think the entire console log may be a little too large to post here, but have a look at the end'ish of it for a start (maybe the last... 40 lines? 50?) - Look for anything about errors or missing. Especially something with Line numbers (error on line 40 for example is a good sign)

If you can't see anything, copy and paste some of it to a post here (but again, just the end, it should be fairly logical, if I remember correctly there is a divide line where the TGB editor info stops and your program output starts)
#8
05/18/2006 (11:58 pm)
I get these two errors

tsm doc should be active

tsm doc Deactivated

and this one

t2dStaticSprite::setImageMap() - t2dImageMapDatablock Datablock is invalid! (playerMissileImageMap)

this one is there a bunch of times i think it was me pressing the spacebar a bunch of times
#9
05/19/2006 (3:31 pm)
Quote:t2dStaticSprite::setImageMap() - t2dImageMapDatablock Datablock is invalid! (playerMissileImageMap)
That's why your missile isn't firing

It can't load the Imagemap for the player missile.

Make sure you missile image is loaded into your Imagemap in your project, and make sure the name matches the name it is looking for in the code (Import the image file "playerMissile" and you should end up with a imageMap called "playerMissileImageMap")
#10
05/19/2006 (10:54 pm)
I have the playermissile image file imported(it is also in the level builder) and i looked at the name and it is what it is suppose to be, maybe it is something else just can't wait for the beat 3 to come to the mac
#11
05/20/2006 (6:08 pm)
Hi!

Having the exact same problem here. The first error I noticed in the console.log was immediately after exec'ing playerMissile.cs:


Loading compiled script shooterTutorial/gameScripts/playerMissile.cs.
Set::remove: Object "LBPlayWindowCtrlStack" does not exist in set
Cannot find menu FormMainMenu for clearMenuItems.

Then there's a plethora of invalid's that follow (cascade effect). I've followed the tutorial and double checked it just as the OP has. There's definitely a problem here and I don't think it's the loose nut behind the keyboard this time!;) Something is missing in the tutorial and/or in the functioning of the level builder.

It's really hard to follow what is going on when everything is behind the scenes. It's nice to have the level builder generate code for us, but it would be nicer if the code were available for perusal for debugging and/or general info. In the previous, more onerous, TGB and tutorial where you had to type in all the .cs code, it was easy to ferret out problems. Here, where they're in data hiding, it's difficult for a tyro like me to see what's going on and what's going wrong.

Someone who's gotten it to work who can definitively state exactly what steps they took to get it to function would be nice to hear from!:-)

thx,
Dave S.
#12
05/21/2006 (8:50 am)
Dave,

Those errors you are seeing in the console are related to the level builder, not the tutorial. The same error messages will pop up if you comment out the exec for playerMissile.cs. While it might be annoying to see them in the console, to date they haven't harmed anything game related I've done. I addressed your "behind the scenes" issue in the suggestion thread you posted but again here: any images/animations added to the create tab are found in the datablocks.cs file in YourProjectName\managed. This file only gets updated after you quit the level builder though. For objects you add to your level, they are found in the YourLevelName.t2d file you (hopefully) saved in YourProjectName\data\levels.

I went through the basic tutorial and just finished the "Fighting is Good" section in part 4. I've copied all script text from the tutorial and pasted it into my script files via Torsion. Up to this point, everything has worked fine, I can shoot missiles and they explode when they collide with the enemy ships.

The only thing I've done that wasn't exactly like the tutorial is change some of the values in the dynamic fields. For example, I reduced the missileSpeed to 500 (still too fast for my liking), and reduced the enemy min/max speeds. The reason for this is probably because my camera view is smaller than the person at GG who wrote the tutorial.
#13
05/21/2006 (2:22 pm)
Hi!

Thanks for your input, both here and under "Suggestions"!;)

I'll try changing the dynamic field values (don't understand how that would affect shooting or no, but anything goes!:-)

My one concern is that so much emphasis is placed on users explaining to other users how to use TGB (!!???)

I'm used to this paradigm with free/share/open software, but not with proprietary purchased software. To me ~$200 is a lot to put out for support that comes from other folks like me who are just feeling their way around...

Since more than one person seems to be having problems with this (and we appear to be new), wouldn't a look-see by a GarageGames staffer be appropriate? I don't mean to be insulting to those who've responded, but if you are someone who's been using TGB for a while, you may be doing something automagically (something you're not consciously aware of) that "fixes" the problem. (?) It is possible. I've done it myself many times in other systems where I just "knew" how to do something and did it without thinking regardless of what was/wasn't in the instructions.

Thanks again for responding!:-)

thx,
Dave S.
#14
05/21/2006 (2:54 pm)
I"ve got this same problem. No errors in the console and the missiles won't fire. :(

In fact, to elaborate, I've gone through and put echo's in the playerMissileFire script to confirm that the missile's coordinates are the same as the pShip's coordinates when the function is called. I've also added the setVisible(true) call to the playerMissileFire function, and made sure the layer is appropriate.

So I'm just not sure what's going on here.
#15
05/22/2006 (4:40 am)
Hi,

Yes, certainly I could be doing something "automagically" that a new user isn't. :)

But without me standing over your shoulder while you all are doing the tutorial it's a bit hard to identify the problem. As I said, I followed the tutorial pretty much word for word and it works for me.

The best I can offer if you are really stuck (this applies to everyone having a problem with the basic tutorial) - is to zip up everything in your shooterTutorial folder (or whatever you called it) and email it to lilligreen (at) gmx (dot) net. I can take a look though it to see what, if anything, differs from my version.

I'm sure someone from GG would also be happy to help, but I'll let them volunteer themselves. ;) The community is a great resource though - it's one of the best things about Torque products.
#16
05/22/2006 (4:46 am)
Hi!

Be glad to do it, but it's the middle of the night for me. I'm soon on my way to bed. So, give me 24 or so to get my ducks in a row and zipped up to send!;) I want to start with a clean slate, try changing the dynamic variable values as you suggested, and if the problem still exists, I'll send what I've got.

Thank you so much for your patience and indulgence!:-)

thx,
Dave S.
#17
05/22/2006 (11:23 am)
Perhaps a more generic question is: how do I go about adding sprites to the level dynamically? There's all sorts of reference material to do stuff with the older T2D, but not much for TGB. When I add the missile, it reports all its parameters (position, layer, etc) properly in the console if I echo the values. But the missile never appears on the screen. Does someone just have a quick demo/example of a blank level, which perhaps after the push of a button, a sprite appears?

Or should I just give up on TGB and use the older T2D tools?
#18
05/22/2006 (11:47 am)
If you've loaded the playerMissle.png into the level builder (from part 1 of the tutorial) then it's dynamically available for your scripts, regardless of if you dragged it into the scene view or not. Using the image builder is basically the same as typing out datablocks, only you get to save yourself the typing and let the image builder do it for you. :) If you see it in the create tab, then it's already referenced in the datablocks.cs file.
#19
05/22/2006 (11:53 am)
This may or may not be the answer for you, but after experiencing the same thing (no missiles appearing), I went back and adjusted my background size to match those of the tutorial and then adjusted the
%this.setWorldLimit( kill, "-55.000 -420.000 600.000 40" ); parameters. Voila - missiles finally appearing. It
seems mine were being "killed" instantaneously. Hope your solution is as easy as mine was.
#20
05/22/2006 (12:01 pm)
^Yup, definitely imported. It doesn't report any errors of the imageMap being missing. (Though I checked to make sure that it does by running a test where I intentionally put in the wrong name.) I'm just completely baffled at this point.

Okay, just saw the world limits approach. I'll try fixing that one tonight. I had a funny error with that involving my ship's world limits. Thanks. :)
Page «Previous 1 2