AddMessageCallback - messageAll VS clientCmd - CommandToClient
by Javier Canon · in Torque Game Engine · 09/10/2007 (11:39 pm) · 3 replies
Hi,
The better way to call functions in client side?:
Using the functions addMessageCallback - messageAll to call a functions in the client side?
or is better use clientCmdXXX, and iterate for each client in server side like:
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameStart');
}
Pros And Cons ?
thanks.
The better way to call functions in client side?:
Using the functions addMessageCallback - messageAll to call a functions in the client side?
or is better use clientCmdXXX, and iterate for each client in server side like:
for( %clientIndex = 0; %clientIndex < ClientGroup.getCount(); %clientIndex++ ) {
%cl = ClientGroup.getObject( %clientIndex );
commandToClient(%cl, 'GameStart');
}
Pros And Cons ?
thanks.
About the author
God blessed me with a brilliant mind... so im a genius...
#2
So if you want to tell all the clients to start the game you might define a client command like this:
And then do something like this on the server side:
So, to answer your question, MessageAll is for sending a very specific client command for chat hud messages, and if you want to send every client an arbitrary command you would want to do what I have shown above.
11/06/2007 (8:30 am)
The server functions messageAll and messageClient are for sending in-game chat hud messages. As you can see from James's code messageAll just loops through all the clients and calls messageClient for each one. The code for messageClient looks likefunction messageClient(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13)
{
commandToClient(%client, 'ServerMessage', %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13);
}The 'ServerMessage' is the function on the client that gets called in this case. Or more specifically the function clientCmdServerMessage.So if you want to tell all the clients to start the game you might define a client command like this:
function clientCmdGameStart()
And then do something like this on the server side:
%count = ClientGroup.getCount();
for(%cl = 0; %cl < %count; %cl++)
{
%client = ClientGroup.getObject(%cl);
CommandToClient( %client, 'GameStart' );
}So, to answer your question, MessageAll is for sending a very specific client command for chat hud messages, and if you want to send every client an arbitrary command you would want to do what I have shown above.
#3
I was confused because in the two ways worked the functions ok.
11/07/2007 (10:25 am)
Thanks for the explanation, in the first time i used messageAll to call functions in the clients, but then i see that is better CommandToClient.I was confused because in the two ways worked the functions ok.
Torque Owner James Laker (BurNinG)
function messageAll(%msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13) { %count = ClientGroup.getCount(); for(%cl = 0; %cl < %count; %cl++) { %client = ClientGroup.getObject(%cl); messageClient(%client, %msgType, %msgString, %a1, %a2, %a3, %a4, %a5, %a6, %a7, %a8, %a9, %a10, %a11, %a12, %a13); } }Whatever you find easier would work.