+1 vote

Hi everyone,

I've just started to code an online multiplayer version for my game.
My pretty common concern is that the game should be playable both offline - it already is - and online, using Godot's High level multiplayer mechanisms.

I'll take the example of the server spawning a ghost at a random position (it's a pacman-like game), and transmitting it to 2 players across the network. Playing offline, the game should simply spawn the ghost.

After reading the doc and a bit of testing, I came up with three ways to go:

rpc only

rpc("spawn_ghost", random_position)

where the spawn_ghost method is defined as remotesync (thus called on both the server and the two clients).
This first method is perfectly fine when playing online, but won't work when playing locally (function is not called).

rpc + local call

rpc("spawn_ghost", random_position)

where the spawn_ghost method is defined as remote or puppet (thus rpc-called on the two clients only, by the server).
This works and synchronises the three parties, but it raises debugger warnings - hundreds of them - about performing rpc() calls while not being online (seems legit).

rpc + local call, under conditions

if online:
  rpc("spawn_ghost", random_position)

(where spawn_ghost is defined as remotesync)
This will work and not raise any debugger warning.


This last solution is pretty cumbersome, because it has to be these same 4 lines of code in many many places in the code (for every synchronised action, that is, most of them).

Did I miss a simple way of calling remote/remotesync/puppet functions that works both online and offline, and is along the lines of how things should be done in Godot? (and, say, a maximum of two lines for each call)

Looking forward to your input, many thanks ind advance!

in Engine by (13 points)

in the Bomber demo that Callnou pointed out, it uses the rpc+local call as in your second example.
However the 2 functions (rpc and local) are defined as master and puppet, havent tried if this is what prevent the debugger to rais warning

puppet func stun():
    stunned = true

master func exploded(_by_who):
    if stunned:
    rpc("stun") # Stun puppets
    stun() # Stun master - could use sync to do both at once

I believe master and puppet are only helpers to prevent one player from calling a function it shouldn't. They also clarify your code as to what methods should be rpc-called by whom.
But they don't prevent the debugger from raising warnings. ;)

1 Answer

+1 vote

You can still start a high-level multiplayer server even if there's only one player. This is what the Multiplayer Bomber demo does.

by (6,936 points)

Hi Calinou,
Thank you very much for your answer!

I think I'll go that way, as it allows for the one-liner rpc("spawn_ghost") if method is set to remotesync.

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 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.