Expose Client side script variable to server.
by Peterjohn Griffiths · in Torque Game Engine · 09/21/2006 (10:07 pm) · 8 replies
Hi,
Can anyone advise on how to expose a client side script variable to the server so that I can access it in the server code below.
I have no idea how the client is created and how variables are added so they are transmitted to the server?.
Do I need to create a commandtoserver call in script and have the server set this variable in the format %Client.myvariable="something" or can this be done on the client?.
Many thanks in advance.
Can anyone advise on how to expose a client side script variable to the server so that I can access it in the server code below.
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
echo ("Client Side Varaible on server=" @ %cl.myvariable);
}I want to set this from script on the client.I have no idea how the client is created and how variables are added so they are transmitted to the server?.
Do I need to create a commandtoserver call in script and have the server set this variable in the format %Client.myvariable="something" or can this be done on the client?.
Many thanks in advance.
#2
I will give it a go during the week.
I may try creating a flexable function and see how much range I can give it.
It would be great to be able to reuse the same function over and over for different variables.
I'll let you know how I get on.
09/23/2006 (5:59 pm)
Thanks, thats great.I will give it a go during the week.
I may try creating a flexable function and see how much range I can give it.
It would be great to be able to reuse the same function over and over for different variables.
I'll let you know how I get on.
#3
09/23/2006 (6:09 pm)
You can 'tag' strings, which makes it available on both sides of the connection as a tag, which is optimized to be as small as possible when being sent. If you will not be sending this variable more than once though, then Hplus is right on track.
#4
Don't forget to detag() before you use the string when you receive it, though!
09/23/2006 (11:00 pm)
Optimizing the variable name using tagging (i e, putting it in the string table) is a fine way of improving throughput if you want to send the same variable often. Tagging a string will not, by itself, transmit any variable change between client and server, though; you need some kind of messaging for that, so I don't quite understand the rest of Stefan's suggestion.Don't forget to detag() before you use the string when you receive it, though!
#5
The OP did not mention if he sends his variable only once or in updates, and whether it changes between updates. I just mentioned one possibility if it is going to travel across the wire alot. For instance, player names in Torque work this way - because they are static and only sent once via packUpdate.
09/24/2006 (3:17 am)
Quote:
Optimizing the variable name using tagging (i e, putting it in the string table) is a fine way of improving throughput if you want to send the same variable often. Tagging a string will not, by itself, transmit any variable change between client and server
The OP did not mention if he sends his variable only once or in updates, and whether it changes between updates. I just mentioned one possibility if it is going to travel across the wire alot. For instance, player names in Torque work this way - because they are static and only sent once via packUpdate.
#6
Many thanks to you both for you help.
09/25/2006 (5:06 am)
As it happends the data I want to send is only to show if a player is ready to start the mission so either way will work great. However I may as well try and use the tag detag method as I may use this for other things like transmitting power ups and weapons etc.Many thanks to you both for you help.
#7
Comparing numbers instead of characters is also significantly faster if all you need to know is ==/!=. Tags could also be used as keys in a map if you're not concerned with sorting order...
09/25/2006 (8:06 am)
If a given string is only going to be displayed once, tag/detag doesn't gain you anything... in fact you loose a little to the tagging overhead (but not much). Tagging is meant to reduce the cost of sending the same strings back and forth, over and over... player names are a great example. Rather than sending char[24] (or whatever) for a player's name over the line every time that name needs to be displayed (chat window, 'X killed Y', whatever), the name can be stored in a table and sent to and fro as an int (32 or 16 bits? I'm guessing 16), saving quite a bit of bandwidth in the long run.Comparing numbers instead of characters is also significantly faster if all you need to know is ==/!=. Tags could also be used as keys in a map if you're not concerned with sorting order...
#8
I have implemented it and all is working fine.
All I did was send a command to the server to update the variable and then have the server send the command to all clients. Each client then changes the status for that player to the new status.
Thanks everyone for all your input, it has been a great help trying to figure this one out.
09/27/2006 (1:03 am)
I have taken a look into this and I think everything I need to do is going to be based around numbers so after Mark's comments I have decided not to use the tag/detag method.I have implemented it and all is working fine.
All I did was send a command to the server to update the variable and then have the server send the command to all clients. Each client then changes the status for that player to the new status.
Thanks everyone for all your input, it has been a great help trying to figure this one out.
Torque Owner J "hplus" W
Warning: don't use "eval" to get the value out of the command, though, as that would be a huge security hole.