Game Development Community

How do Client receive message from sever?

by Jabawork · in Torque Game Engine · 08/19/2006 (2:18 am) · 4 replies

This is a noob question.
I was wondering how client receive message from sever when I use messageClient() function?
Can anyone answer me please? Thx!

#1
08/19/2006 (2:27 am)
What do you mean by 'how'?
-- how the function and call to it need to be configured?
-- how does it happen in the engine?
-- how TCP works? ;-)
#2
08/19/2006 (11:26 am)
"How the function and call to it need to be configured" :p
Sorry, working on English by now.
#3
08/19/2006 (12:13 pm)
First of all you need to have a reference to the client's GameConnection object, call it %client

On the server, use a line of code like this:

commandToClient(%client, 'DoSomething', "hello", 1.2);

Then on the client, this invokes a function called clientCmdDoSomething:

function clientCmdDoSomething(%arg1, %arg2) {
   // code in here...
}

In my example, I have sent 2 arguments to the client: %arg1 receives the value "hello" and %arg2 receives the value 1.2

A very useful construct for invoking a function on all clients is:

for( %i = 0; %i < ClientGroup.getCount(); %i++ ) {
    %cl = ClientGroup.getObject(%i);
    commandToClient(%cl, 'NPCGangArrival', %name);
}

Here I'm telling all connected clients about the arrival of an NPC gang into one of my game's timetrial events

Hope that helps...
#4
08/20/2006 (12:52 am)
This helps alot! Thank you!