Difference Between Client and Server
by Tim Elliott · in Torque Game Engine · 08/31/2005 (2:49 am) · 4 replies
Hi, I have made a couple of small games (usually just small changes to the levels, guns, models etc.), but I have been doing this mainly through tutorials. I am a little confused about the Client/Server idea. Why isnt it all in on one side and what are the difference between server scripts and client scripts.
Thanks in advance
Thanks in advance
About the author
#2
you would make a gui and put all the functionality of the button on the gui in the client. The button, on the client, would need to send a command to the server in order create a new weapon and place it infront of you.
example of client's code
I hope that helps
08/31/2005 (5:00 am)
Client scripts deal mostly with user interface, server on the other hand does all the gameplay physics and interactions. so for instance if you wanted a screen to allow weapons to be dropped infront of you.you would make a gui and put all the functionality of the button on the gui in the client. The button, on the client, would need to send a command to the server in order create a new weapon and place it infront of you.
example of client's code
new GuiChunkedBitmapCtrl(dropWeaponGui) {
profile = "GuiContentProfile";
horizSizing = "width";
vertSizing = "height";
position = "0 0";
extent = "640 480";
minExtent = "8 8";
visible = "1";
bitmap = "./background";
useVariable = "0";
tile = "0";
curScene = "1";
helpTag = "0";
new GuiBitmapButtonCtrl(dropweaponButton) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "64 340";
extent = "64 64";
minExtent = "8 2";
visible = "1";
command = "dropWeaponGui.drop();";
text = "Drop Weapon";
groupNum = "-1";
buttonType = "PushButton";
bitmap = "./drop";
};
};
function dropWeaponGui::drop(%this){
commandtoserver('dropweapon');
}and for the serverfunction serverCmdDropWeapon(%client){
%weapon = new Item(){
datablock = Crossbow;
};
MissionCleanup.add(%weapon);
//place in front o player of the client.
%playerTran = %client.player.getTransform();
%playerPos = getWords(%playerTran, 0, 2);
%playerRes = getWords(%playerTran, 3, 4);
%offset = "0 5 0";
%newPos = vectorAdd(%playerPos, %offset);
%newTran = %newPos SPC %playerRes;
%weapon.setTransform(%newTran);
} I hope that helps
#3
If you then try to set up a lan version of your game and have more people join in, then you'll soon find out that using server scripts to create guis doesn't work. As clients join your server, they don't start the server scripts so they won't execute that code. Same thing with writing client side code that modifies server variables -- it won't work because the server doesn't start client processes (unless the server is also a client). But in the case where a client is also a server, the only client scripts that exist are the client that is the server.
So, it is best to maintain that separation at all times. Use the client to perform processing on the client side only. If you need to modify something on the server, either use the server commands or modify the SDK and learn net events. The same goes for server side processing -- don't do any client side processing. Instead, call client side code using client commands or use net events.
In script, the enforcement of client and server isn't as strict as it is in C++ code. Things that will work in script (modifying a server variable from a client script) will work. However, in C++ that isn't usually the case. So, always remember to keep them separate.
Server: gameplay, physics, scoring, event distribution, moves processing
Client: Visual presentation (rendering), user interface, move interpolation
- Brett
08/31/2005 (6:31 am)
In a multiplayer environment, which is what Torque is written for, client and server are separate processes. Even when you create a single player experience, you're going to be running in this client/server setup. You'll find that when the server and the client exist in the same machine, there isn't much difference between the two. You can write scripts that were started by the server side, that draw guis on the client side. Of course, this isn't the best approach.If you then try to set up a lan version of your game and have more people join in, then you'll soon find out that using server scripts to create guis doesn't work. As clients join your server, they don't start the server scripts so they won't execute that code. Same thing with writing client side code that modifies server variables -- it won't work because the server doesn't start client processes (unless the server is also a client). But in the case where a client is also a server, the only client scripts that exist are the client that is the server.
So, it is best to maintain that separation at all times. Use the client to perform processing on the client side only. If you need to modify something on the server, either use the server commands or modify the SDK and learn net events. The same goes for server side processing -- don't do any client side processing. Instead, call client side code using client commands or use net events.
In script, the enforcement of client and server isn't as strict as it is in C++ code. Things that will work in script (modifying a server variable from a client script) will work. However, in C++ that isn't usually the case. So, always remember to keep them separate.
Server: gameplay, physics, scoring, event distribution, moves processing
Client: Visual presentation (rendering), user interface, move interpolation
- Brett
Torque 3D Owner Sebastien Bourgon
Server scripts are executed when a server is started. This is either at start on a dedicated server or a call to startServer made by a client when they host a game (either multiplayer or singleplayer);
So on a client playing on a dedicated, it only has the client set executed and loaded.
Dedicated servers would have only had the server set executed.
HOSTING Clients would have BOTH server and client code executed. Which means they have access to all the functions through console and script.