Accessing player object in TorqueScript
by Matthew Harris · in Torque Game Engine · 04/07/2006 (9:43 am) · 3 replies
How do I access my player object in torque script. I know the player is created in GameConnection::createPlayer and they use the %player variable. How would I use this object in another function/cs file.
#2
04/07/2006 (9:45 am)
Im a bit confused, do you have example code.
#3
So if your trying to get to the player within a GameConnection:: function after createPlayer() has been called you can do this:
Be aware that getControlObject() would return the camera if your in the free camera mode, so unless the stuff your doing should apply to both stick to %this.player.
Now if your outside of a GameConnection:: function it gets tricky. If your strictly single player you can add this at the end of GameConnection::createPlayer():
Now you should be able to use $player from any server script after the player is setup.
04/07/2006 (9:59 am)
@Matthew - Where are you trying to access the player from? You'll notice that in GameConnection::createPlayer() it does this near the bottom:%this.player = %player; %this.setControlObject(%player);
So if your trying to get to the player within a GameConnection:: function after createPlayer() has been called you can do this:
echo( %this.player.getPosition() ); // or echo( %this.getControlObject().getPosition() );
Be aware that getControlObject() would return the camera if your in the free camera mode, so unless the stuff your doing should apply to both stick to %this.player.
Now if your outside of a GameConnection:: function it gets tricky. If your strictly single player you can add this at the end of GameConnection::createPlayer():
%this.player = %player; %this.setControlObject(%player); $player = %player;
Now you should be able to use $player from any server script after the player is setup.
Torque Owner Stefan Lundmark