Game Development Community

How to tell if a script is executing on client or server ?

by Orion Elenzil · in Torque Game Engine · 12/12/2005 (11:02 am) · 3 replies

I'd like to be able to do something like this in script:

function foo()
{
echo("executing on server:" SPC isExecutingOnServer());
}


searching for related keywords just turns up such an immense slew of stuff it's hard to sift thru.

tia,
orion

#1
12/12/2005 (12:01 pm)
A script executing on a Server or a Client can be a little confusing.

In your echo("executing on server:") example simply prints "executing on server" (as I'm sure you know). It will execute on the server if you have your current executable functioning as a server (in your console) , or it will execute on the client if your current executable is functioning as the client (shown in the GUI console / and your window console).

Or both! If you're running a server and client on the same machine (a single player game), your current script machine will have all of the functionality of a server and a client.

So really - when you echo(); you see the results on your script machine, which depending on how you've set it up is either "on the Server" or "on the Client".

There's an entire TDN article I started (and it's done until someone makes corrections) here

Hope it helps

- Eric
#2
12/12/2005 (12:23 pm)
Hey Eric,
thanks for the reply.

I actually read your TDN article a bit before posting.
Very nice article, very informative.

So via your article and some experiments i realized finally that it's basically all muddled together when you've got one .exe instance functioning as both server and client, due to there not being a seperate set of variables.

For example,
if you set a global script variable $AmServer = "sure am!" in say server/init.cs
and then echo the value in client/init.cs, it answers "sure am!" instead of (undefined).

So, it's good to know.

Aha, and just discovered gClientContainer vs. gServerContainer!
Also good to know.
#3
12/13/2005 (5:54 am)
Scripts are actually quite easy for a large majority: if they are in the /client dir, then they will always be running on the client side, and if on the /server side, the server. This gets a little bit more confusing with the /common or /creator dir, but for the most part it is pretty obvious.

Of course, on the c++ side, you have the object methods isServerObject() and isClientObject(), and you could certainly expose these to script via ConsoleMethod if your project has the need.