Page 1 of 1

A short question. Where is the flag to check if the code runs on server or client?

Posted: Fri Apr 23, 2021 3:03 am
by yagaodirac
Thanks.

Re: A short question. Where is the flag to check if the code runs on server or client?

Posted: Fri Apr 23, 2021 4:55 am
by boskid
There is no such thing as a flag that tells you if code runs on server or not. There was never a need for such a thing and there is no reason to have something like that. Reason is simple: you should never ever change your script behavior on that, because in multiplayer your script is in fact being executed in muliple instances synchroniously at the same time: on the server and on all of the connected clients. If those multiple instances would at any point in time produce an observable difference in game state, then the game desyncs and a client for which script gave a different result is disconnected from the server.

Re: A short question. Where is the flag to check if the code runs on server or client?

Posted: Fri Apr 23, 2021 5:09 am
by yagaodirac
boskid wrote:
Fri Apr 23, 2021 4:55 am
Thanks for replying.
The purpose is that, I need to display something for players. They are trivial and not worthy any memory on server.
But if there is not such a mechanism, it's the same for me to do it in a unified script and cost some extra memory on server.

Re: A short question. Where is the flag to check if the code runs on server or client?

Posted: Fri Apr 23, 2021 5:24 am
by boskid
yagaodirac wrote:
Fri Apr 23, 2021 5:09 am
The purpose is that, I need to display something for players. They are trivial and not worthy any memory on server.
But if there is not such a mechanism, it's the same for me to do it in a unified script and cost some extra memory on server.
By doing that you would literally produce a desync. Things that are displayed to the player are (almost) always a part of game state so if an instance on the player to which you want to print would game.print a message (=change game state) while the server would not follow the same print code, game state would diverge and desync would occur.

I see no reason in trying to optimize memory usage so much on particular instances. Having all instances produce the same output is by far the most important thing and if that requires more memory then i am fine with that.

Re: A short question. Where is the flag to check if the code runs on server or client?

Posted: Sun May 09, 2021 6:44 am
by yagaodirac
boskid wrote:
Fri Apr 23, 2021 5:24 am
OK, thanks.
The feature is already done and works properly and not causes any heavy performance issue.