Sending array
by Rudolf Kajan · in Torque Game Engine · 01/05/2007 (4:43 am) · 5 replies
I have problem with sending array from server to client
server :
function serverCmdGimmeQuestsStatus( %client)
{
$num = 2;
$aaa[0]="aaa";
$aaa[1]="bbb";
commandToClient(%client,'QuestsStatus',$num,$aaa);
}
client:
function clientCmdQuestsStatus($num,$aaa)
{
echo($num);
echo($aaa[0]); //tried also echo($aaa); - didn't work
}
console output:
...
...
2
...
...
server :
function serverCmdGimmeQuestsStatus( %client)
{
$num = 2;
$aaa[0]="aaa";
$aaa[1]="bbb";
commandToClient(%client,'QuestsStatus',$num,$aaa);
}
client:
function clientCmdQuestsStatus($num,$aaa)
{
echo($num);
echo($aaa[0]); //tried also echo($aaa); - didn't work
}
console output:
...
...
2
...
...
About the author
#2
01/05/2007 (5:01 am)
OK, thanks
#3
01/05/2007 (1:38 pm)
Brian states the best method. Take your array and convert it to a TAB seperated list, then send the list. The client can then convert that list back into an array on their end. The other way, is to loop through the array, sending a commandToClient for each index. This method will send as you can imagine, a lot of network traffic. I would use the Tabbed List method. Oh and tag the list before sending "compressed".
#4
01/05/2007 (3:28 pm)
If you're limited to scripts then the above is the best solution, if you have the ability to go into code then I suggest NetEvents. Good luck.
#5
01/06/2007 (3:49 am)
Ok, I'll try, thanks everyone
Torque Owner Brian Hill
To send array data, I'd create a tab and return delimited string and send that. Then on the client side, use 'getRecord' and 'getWord' to parse out the data items.
Like this:
%linestring = getRecord(%string,%recordNum);
%field = getWord(%linestring,%fieldNum);