Hi!
I’m using Godot 4.2.1 and am dipping my toes in networking. So far, I have my phone “connect” to my laptop using the following script:
func _ready():
multiplayer.connected_to_server.connect(server_connected)
func _on_join_pressed():
var address: String = %Address.text
var port: int = int(%Port.text)
var error = MultiplayerHandler.join_server(address, port)
if error:
OS.alert(error_string(error) + " (" + str(error) + ")")
return
func server_connected():
get_tree().change_scene_to_file("res://menus/pre_start_menu/pre_start_menu.tscn")
Now, as you can see, I catch any errors and show them using OS.alert()
. This doesn’t happen, so the multiplayer_peer
gets created correctly. But the connected_to_server
signal doesn’t get emitted, and nothing comes up on my server too.
Here’s also the MultiplayerHandler
, which is an autoload:
extends Node
# Returns error
func join_server(address: String, port: int):
var peer := ENetMultiplayerPeer.new()
var error = peer.create_client(address, port)
if error:
return error
multiplayer.multiplayer_peer = peer
Yeah, I basically copied it from the docs.
So, yeah, I really don’t know where the error could be.