A short question. Where is the flag to check if the code runs on server or client?
-
- Fast Inserter
- Posts: 152
- Joined: Sun Jun 16, 2019 4:04 pm
- Contact:
Re: A short question. Where is the flag to check if the code runs on server or client?
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.
-
- Fast Inserter
- Posts: 152
- Joined: Sun Jun 16, 2019 4:04 pm
- Contact:
Re: A short question. Where is the flag to check if the code runs on server or client?
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?
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.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.
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.
-
- Fast Inserter
- Posts: 152
- Joined: Sun Jun 16, 2019 4:04 pm
- Contact: