Scripting tab. But then the player.cs script has this: function playerShip::onLevelLoaded(%this, %scenegraph) { $pSh"> Shooter tutorial confusion - pShip | Torque Game Builder | Forums | Community | GarageGames.com

Game Development Community

Shooter tutorial confusion - pShip

by Vern Jensen · in Torque Game Builder · 06/17/2006 (2:48 pm) · 3 replies

One small thing I don't understand yet about the Shooter tutorial. It has us name the player's ship sprite "pShip" in the Edit-->Scripting tab. But then the player.cs script has this:

function playerShip::onLevelLoaded(%this, %scenegraph)
{
$pShip = %this;
...
}

As I understand it, this creates a new global variable pShip to keep track of this ship. So then what was the pShip in the Edit--->Scripting tab for? If I change that to some other name, everything still seems to run correctly... Are those two things both doing the same thing, or does naming an object in the Edit tab have a different purpose than the line of code above?

-Vern

#1
06/17/2006 (3:42 pm)
Object can have names as well has global variables. If the name was "superCoolShip", "superCoolShip.someFunction()" would be the same as "$pship.someFunction()". Its just 2 ways of referenceing the same object. I guess as changing the name doesn't effect anything that the tutorial uses the global variables in it's calls and the name is just there for sake of completness.
#2
06/17/2006 (10:38 pm)
Okay, that's even more confusing to me then, because the tutorial says to copy and paste enemy ships to make more of them. This resuls in them all having the same name. If it's true that you can reference a sprite by its name, and you have 5 on-screen with exactly the same name, what happens if you do, as you suggested:

superCoolShip.someFunction();

Will it call that function for all 5 ships, since 5 are on screen with that name? That would seem unlikely...

-Vern
#3
06/17/2006 (11:59 pm)
I think it will work on the most recent one created with that name, hence why global variables are used. Global variables reference the ID of an object which is unique so if there is a global variables assigned use that.