I want to do a multiplayer games but it is hard to really understand how it works.
I did refer the official tutorial from Godot here. but I still can’t understand it then I read the code example of multiplayer bomber.
From the multi player bomber, I just extracted when a lobby is created by Host and then a Player joins the lobby.
I did this to simplify the GDScript so I can focus on understanding its inner working.
Besides I add additional print() to see which function is called first and understand their sequence. To know the sequence I added timestamp when the function is called.
Example:
1 |
print("game state - register player() ", id, " time stamp: ", OS.get_system_time_msecs()) |
I also rearrange the scripts into different folder to reflect its purposes and change gamestate.gd to GameState.gd
Print at Critical Functions To Detect Functions Calling Sequence
scripts/global/GameState.gd
- print(“game state – connected_ok()”, ” time stamp: “, OS.get_system_time_msecs())
- print(“game state – player connected(). ID: “, id, ” time stamp: “, OS.get_system_time_msecs())
- print(“game state – register player() “, id, ” time stamp: “, OS.get_system_time_msecs())
scripts/lobby/lobby.gd
- print(“game state – register player() “, id, ” time stamp: “, OS.get_system_time_msecs())
- print(“lobby – refresh_lobby() Players: “, players, ” time stamp: “, OS.get_system_time_msecs())
- print(“lobby – _on_connect_success()”, ” time stamp: “, OS.get_system_time_msecs())
A Player Joins As Host @ Server
When a player joins as host, below is the print output.
Launch The Application
- Run the application via command line (I’m using Linux)
- Then click Host

Host / Server output:
As you can see, no network signals (network_peer_connected & connected_to_server) are emitted during the network server connections.

A Player Joins as Client
When a player joins as client, below is the print output.

Host / Server output:

Player / Client output:

Print Output Timestamp Sequence
I rearrange the print out timestamp based on which comes first. Below is the result.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
CLIENT game state - player connected(). ID: 1 time stamp: 1618724339580 - netwoork (rpc to register player()) game state - connected_ok() time stamp: 1618724339580 - emit connection succeed lobby - _on_connect_success() time stamp: 1618724339580- from signal connection_succeed connect hide SERVER game state - player connected(). ID: 741208717 time stamp: 1618724339596 - netwoork (rpc to register player()) game state - register player() 741208717 time stamp: 1618724339597 - emit "player_list_changed lobby - refresh_lobby() Players: [p2] time stamp: 1618724339597 CLIENT game state - register player() 1 time stamp: 1618724339613 lobby - refresh_lobby() Players: [wanrazali] time stamp: 1618724339613 |
Notes:
The timestamp here differs from screenshots as I did this article in few days, hence the difference in timestamps.
Sequence Diagram
From the “Print Output Timestamp Sequence”, I developed the sequence diagram for better visualization.

Key Take Aways
- A put “remote” if the function is called by rpc_id() or any functions called via rpc
- Functions within the same entity e.g Client or Server are executed first.
- Function called via rpc() is executed after all functions within same entity is executed.
- Even function triggered via emit signal is executed first before rpc()