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)
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)
else:
spawn_ghost(random_position)
(where spawn_ghost is defined as remotesync
)
This will work and not raise any debugger warning.
Solution?
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!