%client.playerName problem
by Christian Weber · in Torque 3D Beginner · 11/18/2009 (7:54 am) · 7 replies
Hey everyone,
I'm having a small issue. Beware of the bad source, I'm totally new to TS, just began yesterday. However I made working Team and Class Selection system. Now I noticed a small issue. In my Class selection function (on the server) I have the following code:
In the messageAll function it works without a problem, it just sends the users name like expected. But in the echo there is just a 14 instead of the users name? Same thing at the makeReady function that gets called.
Can someone tell me what I'm doing wrong? :(
Thanks in advance.
Best Regards,
Chris
I'm having a small issue. Beware of the bad source, I'm totally new to TS, just began yesterday. However I made working Team and Class Selection system. Now I noticed a small issue. In my Class selection function (on the server) I have the following code:
function serverCmdClass(%client,%data) {
echo("$Game::running: "@game);
echo(%client.playerName@" has chosen his class");
if(%client.team != 0 && (%data == 1 || %data == 2)) {
if(%client.team == 1) {
switch(%data) {
case 1: messageAll('MsgClientClassChosen','\c2%1(%2) is going to fight as Soldier!',%client.playerName,%client.rank);
case 2: messageAll('MsgClientClassChosen','\c2%1(%2) is going to fight as Officer!',%client.playerName,%client.rank);
}
} else {
switch(%data) {
case 1: messageAll('MsgClientClassChosen','\c1%1(%2) is going to fight as Soldier!',%client.playerName,%client.rank);
case 2: messageAll('MsgClientClassChosen','\c1%1(%2) is going to fight as Officer!',%client.playerName,%client.rank);
}
}
%client.class=%data;
commandToClient(%client,'ClassChosen');
game.makeReady(%client);
//$Game::makeReady(%client);
} else {
commandToClient(%client,'ChooseTeam');
}
}In the messageAll function it works without a problem, it just sends the users name like expected. But in the echo there is just a 14 instead of the users name? Same thing at the makeReady function that gets called.
Can someone tell me what I'm doing wrong? :(
Thanks in advance.
Best Regards,
Chris
About the author
#2
11/18/2009 (9:28 am)
Ok i got it :-/ getTaggedString(%client.playerName); solves the problem. :)
#3
Where did you put the getTaggedString part to get it to work. I've been trying since TGE to echo a player name, never asked though as it wasn't that important.
11/18/2009 (2:22 pm)
Christian, you managed to get this part to work?echo(%client.playerName@" has chosen his class");
Where did you put the getTaggedString part to get it to work. I've been trying since TGE to echo a player name, never asked though as it wasn't that important.
#4
It is hard to see sometimes, but in the script code you will see strings which have "text" and some strings which are like 'other text' (note the single quotes). The single quote indicates a tagged string. Tagged strings are for strings which would need to be transmitted several times over the wire. Instead of transmitting the full string each time, it creates a string ID, sends the whole string once, and after simply sends that string ID. It is very useful.
11/18/2009 (2:29 pm)
You will want to do:echo(getTaggedString(%client.playerName) @ " has chosen his class");
It is hard to see sometimes, but in the script code you will see strings which have "text" and some strings which are like 'other text' (note the single quotes). The single quote indicates a tagged string. Tagged strings are for strings which would need to be transmitted several times over the wire. Instead of transmitting the full string each time, it creates a string ID, sends the whole string once, and after simply sends that string ID. It is very useful.
#5
11/18/2009 (3:39 pm)
As far as I undestood it is to reduce the network packages? As most functions don't need the whole data, some data gets tagged. Those are just transmitted as ids so you can still get them via the "getTaggedString" function, if needed. Don't know if this is totally correct, but it helped me to understand why taggedStrings are very useful. Didnt know a reason to use them before too.
#6
So in the example you posted:
This may help (or may confuse you more), but a tagged string is like a networked hashtable. All the clients/server share the same table (tagged strings), and so instead of having to re-send the whole string any time it is needed, they simply send the key (the tag id) and the client/server can just look up the string in the table using that key.
11/18/2009 (4:05 pm)
Right.So in the example you posted:
messageAll('MsgClientClassChosen','\c2%1(%2) is going to fight as Soldier!',%client.playerName,%client.rank);That first string 'MsgClientClassChosen' is a tagged string. It is a message name, and will not change, so instead of sending the full name of the command each time it is executed, it sends only an ID value, and then the clients can look up the string. The same with the message string...that message string does not change, so it simply assigns an ID to that string, and than looks up the ID instead of sending the whole string.This may help (or may confuse you more), but a tagged string is like a networked hashtable. All the clients/server share the same table (tagged strings), and so instead of having to re-send the whole string any time it is needed, they simply send the key (the tag id) and the client/server can just look up the string in the table using that key.
#7
However, in the file core\scripts\server\clientConnection.cs (in T3D) or common\serverScripts\clientConnection.cs (in TGEA), the function GameConnection::onConnect( %client, %name ) takes the name from the client and sets it into the NetConnection with the method %client.setPlayerName(). That, in turn, sets the name as is into %client.nameBase, and as a tagged string into %client.playerName (in TGEA, this was just %client.name). That is, of course, why %client.playerName was echoed as a number. And yes, getTaggedString() will convert any tagged string ID to a normal string, whereas detag only works for functions receiving tagged strings.
All tagged strings start with the engine-defined single character called "StringTagPrefixByte". The difference (and you can see this if you take a look at the values of these strings during a break point in Torsion) is what follows. %client.playerName is stored as a string with the tag ID number following the prefix byte. This is the type of string to use getTaggedString() with. But when received in a function after transmission, the number following the prefix has been replaced by the actual string. This is the type of string that detag is for.
Regardless, when you want to read (or echo) it on the server side, you should be able to use %client.nameBase as is and not have to worry about tags. But for a function like MessageClient, where it will be sent over the network, you would want to use %client.playerName since it is tagged.
11/29/2009 (3:13 am)
Remember, in a serverCmd, the %client argument is not the actual client, per se, but the NetConnection to the client. It is still, however, a server-side object, thus normally tagging/detagging should not generally apply to the fields of that object.However, in the file core\scripts\server\clientConnection.cs (in T3D) or common\serverScripts\clientConnection.cs (in TGEA), the function GameConnection::onConnect( %client, %name ) takes the name from the client and sets it into the NetConnection with the method %client.setPlayerName(). That, in turn, sets the name as is into %client.nameBase, and as a tagged string into %client.playerName (in TGEA, this was just %client.name). That is, of course, why %client.playerName was echoed as a number. And yes, getTaggedString() will convert any tagged string ID to a normal string, whereas detag only works for functions receiving tagged strings.
All tagged strings start with the engine-defined single character called "StringTagPrefixByte". The difference (and you can see this if you take a look at the values of these strings during a break point in Torsion) is what follows. %client.playerName is stored as a string with the tag ID number following the prefix byte. This is the type of string to use getTaggedString() with. But when received in a function after transmission, the number following the prefix has been replaced by the actual string. This is the type of string that detag is for.
Regardless, when you want to read (or echo) it on the server side, you should be able to use %client.nameBase as is and not have to worry about tags. But for a function like MessageClient, where it will be sent over the network, you would want to use %client.playerName since it is tagged.
Torque Owner Christian Weber
HydraGames
But how can I get a clients name?