Obtain ID
by Manuel M · in Torque 3D Professional · 04/11/2010 (3:29 pm) · 4 replies
Hello.
I have created a function to animate my player character. The problem is that the ID, changes each time I reload the map. I don't know how obtain the player id, or the id of other object. How I can do this?
The idea is obtain the id with some function and then apply this id in other function.
I have created a function to animate my player character. The problem is that the ID, changes each time I reload the map. I don't know how obtain the player id, or the id of other object. How I can do this?
The idea is obtain the id with some function and then apply this id in other function.
#2
04/11/2010 (8:06 pm)
Thanks for you reply. I will try your method. A question, how can I save the player in global variable?
#3
In the server:
In the client:
But not work, the consol reported that: Unkown command setActionthread
In the client, the command "setActionthread" it works, Why don't works in the server? and the local variable %client is not defined, already is defined as Player?. Ah, and I don't have the file "gameCore.cs", only in the full template, I used "empty template". Can there be any problem with this?
EDIT:
Now works:
In server:
In client:
04/11/2010 (10:09 pm)
Hello again, I created this code:In the server:
if (%animation == "Idle"){
%client.setActionthread(%animation, true);
}
if (%animation == "Walk"){
%client.setActionthread(%animation, true);
}In the client:
function anim(%animation)
{
commandToServer('Anim', "Walk");
}But not work, the consol reported that: Unkown command setActionthread
In the client, the command "setActionthread" it works, Why don't works in the server? and the local variable %client is not defined, already is defined as Player?. Ah, and I don't have the file "gameCore.cs", only in the full template, I used "empty template". Can there be any problem with this?
EDIT:
Now works:
In server:
function serverCmdAnim(%client, %animation)
{
%client.Player.setActionThread(%animation);
}In client:
function anim(%animation)
{
commandToServer('Anim', %animation);
}
#4
Edit:
To answer your previous question, you can access the LocalClientConnection from anywhere, or use callbacks that specifiy the object(or player) in question. I guess I wouldn't really use globals unless its necessary, but if you so desire: in your gamecore.cs (or game.cs in TGE), the spawnplayer function should have the newly created "player" held in a variable: %player; just set it up like so:
$hero = %player;
then you can call your player anywhere
HTH
04/13/2010 (2:48 pm)
LocalClientConnection.player in server Edit:
To answer your previous question, you can access the LocalClientConnection from anywhere, or use callbacks that specifiy the object(or player) in question. I guess I wouldn't really use globals unless its necessary, but if you so desire: in your gamecore.cs (or game.cs in TGE), the spawnplayer function should have the newly created "player" held in a variable: %player; just set it up like so:
$hero = %player;
then you can call your player anywhere
HTH
Torque 3D Owner Marcus L
As for my solution you can add this code after the line $Server::PlayerCount++; in function GameConnection::onConnect(%client, %name) (gameCore.cs):
if($Server::PlayerCount == 1) $Server::Player1 = %client; if($Server::PlayerCount == 2) $Server::Player2 = %client; if($Server::PlayerCount == 3) $Server::Player3 = %client; if($Server::PlayerCount == 4) $Server::Player4 = %client;Using this code will make the first player joining $Server::player1 and the next $Server::player2 etc, but this is only the clients ID so to return the players ID is using my method you'll need to add $Sever::player1.player on the end. Just to repeat my self; the best method is to use local variables like %client, but this is not always possible (and those cases are the cases when you have to be creative).