RPC now works

This commit is contained in:
Paul Black 2023-02-21 13:34:05 -07:00
parent ec05c7d61a
commit a7ce62450a
2 changed files with 8 additions and 8 deletions

View file

@ -43,8 +43,8 @@ func _on_join_button_pressed():
printerr("Did NOT connect to server")
$errorLabel.text = "Did NOT connect to server"
if result == OK:
print("Connected to server at IP ", IPADD, ":", intPORT, "!")
$errorLabel.text = "Connected to server!"
print("Connecting to server at IP ", IPADD, ":", intPORT, "...")
$errorLabel.text = "Connecting to server..."
multiplayer.multiplayer_peer = peer

View file

@ -2,7 +2,7 @@ extends Node
var peer = ENetMultiplayerPeer.new()
var SCENE = "res://scenes/playground.tscn"
var connected_peers = []
func create_server(port, maxPlayers):
var result = peer.create_server(port, maxPlayers) # Second paramater specifies the player limit. Can be anything between 1 and 4095
@ -19,9 +19,9 @@ func create_server(port, maxPlayers):
peer.peer_connected.connect(
func(new_peer_id):
print("NEW CONNECTION FROM ", new_peer_id)
#await get_tree().create_timer(1).timeout ## Might not be required anymore...
#add_newly_connected_player_character()
rpc("add_newly_connected_player_character")
await get_tree().create_timer(0.5).timeout ## REQUIRED, THE RPC IS MADE BEFORE THE CLIENT IS FULLY CONNECTED
connected_peers.append(new_peer_id)
rpc_id(new_peer_id, "add_newly_connected_player_character")
)
func load_map(map):
@ -30,6 +30,6 @@ func load_map(map):
@rpc("any_peer", "call_remote")
func add_newly_connected_player_character():
print("add_newly_connected_player_character() has been run!")
print("Connected to server!")
load_map(SCENE)
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)