Ummm... how do I do this?
by Jason Haden · in Technical Issues · 09/20/2008 (11:35 pm) · 8 replies
How do you refer to the player in Torquescript from a seperate object?
I need it to make Tails follow Sonic.
I've tried %player, but it doesn't work.
I need it to make Tails follow Sonic.
I've tried %player, but it doesn't work.
#2
If you want to have a player object that's accessible from ALL functions, use $player instead. If you have a player graphic, then you can give it a class and do something like this:
function playerClass::onAddToScene (or function playerClass::onSceneLoaded)
{
$player = %this;
}
09/21/2008 (3:28 am)
%player is a local variable and will only work within the function in which it was declared.If you want to have a player object that's accessible from ALL functions, use $player instead. If you have a player graphic, then you can give it a class and do something like this:
function playerClass::onAddToScene (or function playerClass::onSceneLoaded)
{
$player = %this;
}
#3
in $player become the last player anytime
09/21/2008 (4:15 pm)
$player = %this; This is good only for single player gamesin $player become the last player anytime
#4
09/22/2008 (2:19 pm)
I've named player from login, so i do a create like this: new player (%nickname){..}. The advatage is i can access all players by nickname. For example %nickname is tom i can do a tom.setscale("0.5 0.5 0.5")
#5
You could do:
new player(%nickname){...}
%nickname.setscale....
But again %nickname will only be visible within that function that defined it.
09/22/2008 (3:29 pm)
You wouldn't want to hardcode anything in your program (tom.setscale...) if it depends on what a user enters. You have no idea what their login will be, so you have no idea what to name your objects.You could do:
new player(%nickname){...}
%nickname.setscale....
But again %nickname will only be visible within that function that defined it.
#6
So...
09/22/2008 (4:51 pm)
I don't know how it is in the particular version of the engine you're using, but you can in a lot of cases grab the player out of the client connection. The idea being you can pass in the client connection to the function where you need your player, and get it from there without having to do something hacky like having a global $player variable.So...
function TailsObject::follow( %this, %client )
{
%player = %client.player;
// No player, nothing to do.
if ( !isObject( %player ) )
return;
// Do whatever you need
// to do to follow the %player object.
}
#7
03/22/2009 (7:21 pm)
Here is a good question... Are you using TGB or TGE?
#8
03/24/2009 (1:29 pm)
I was a n00b when I posted this! OMG! I was soooo stupid! I was using TGE, and didn't know about local/global variables!
Torque 3D Owner Michael Chew
Like this?
%sonic = new Playerer()
{
...
};
Then %sonic contains the id of the player object.