0 votes

How do you make sure that a function is only executable on the server?
I don't want to do a simple gettree().isnetwork_server() check because it doesn't feel safe enough, I would prefer for a function to be completely unaccessible for clients.

in Engine by (26 points)

There is no #ifdef like in C++ or C#, so if you want to make it completely unavailable, you can make two Godot projects. One for the server, and one for the client. But I find this a bit unpractical for sharing code.
If you keep the same project, whatever you do using GDScript, you'll have to use is_network_server at some point. Either to call a function or not, or to instance a manager or another.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.