Skip to content

Commit 8ce770e

Browse files
authored
Merge pull request godotengine#7826 from Jordyfel/lobby-example-patch
2 parents 38f9635 + 49a6228 commit 8ce770e

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

tutorials/networking/high_level_multiplayer.rst

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,11 @@ The function ``multiplayer.get_remote_sender_id()`` can be used to get the uniqu
232232
transfer_some_input.rpc_id(1) # Send the input only to the server.
233233

234234

235-
@rpc("any_peer", "call_local", "reliable") # Call local is required if the server is also a player.
235+
# Call local is required if the server is also a player.
236+
@rpc("any_peer", "call_local", "reliable")
236237
func transfer_some_input():
237-
var sender_id = multiplayer.get_remote_sender_id() # The server knows who sent the input.
238+
# The server knows who sent the input.
239+
var sender_id = multiplayer.get_remote_sender_id()
238240
# Process the input and affect game logic.
239241

240242
Channels
@@ -272,12 +274,14 @@ have loaded the game scene.
272274
const DEFAULT_SERVER_IP = "127.0.0.1" # IPv4 localhost
273275
const MAX_CONNECTIONS = 20
274276

275-
# This will contain player info for every player, with the keys being each player's unique IDs.
277+
# This will contain player info for every player,
278+
# with the keys being each player's unique IDs.
276279
var players = {}
277280

278-
# This is the local player info. This should be modified locally before the connection is made.
279-
# It will be passed to every other peer.
280-
# For example, the value of "name" can be set to something the player entered in a UI scene.
281+
# This is the local player info. This should be modified locally
282+
# before the connection is made. It will be passed to every other peer.
283+
# For example, the value of "name" can be set to something the player
284+
# entered in a UI scene.
281285
var player_info = {"name": "Name"}
282286

283287
var players_loaded = 0
@@ -293,7 +297,7 @@ have loaded the game scene.
293297

294298

295299
func join_game(address = ""):
296-
if address == "":
300+
if address.is_empty():
297301
address = DEFAULT_SERVER_IP
298302
var peer = ENetMultiplayerPeer.new()
299303
var error = peer.create_client(address, PORT)
@@ -317,7 +321,8 @@ have loaded the game scene.
317321
multiplayer.multiplayer_peer = null
318322

319323

320-
# When the server decides to start the game from a UI scene, do Lobby.load_game.rpc(filepath)
324+
# When the server decides to start the game from a UI scene,
325+
# do Lobby.load_game.rpc(filepath)
321326
@rpc("call_local", "reliable")
322327
func load_game(game_scene_path):
323328
get_tree().change_scene_to_file(game_scene_path)
@@ -347,7 +352,7 @@ have loaded the game scene.
347352

348353

349354
func _on_player_disconnected(id):
350-
player_info.erase(id)
355+
players.erase(id)
351356
player_disconnected.emit(id)
352357

353358

@@ -363,6 +368,7 @@ have loaded the game scene.
363368

364369
func _on_server_disconnected():
365370
multiplayer.multiplayer_peer = null
371+
players.clear()
366372
server_disconnected.emit()
367373

368374
The game scene's root node should be named Game. In the script attached to it:

0 commit comments

Comments
 (0)