Godot Version
v4.2.2.stable.arch_linux
Question
Hey there everyone, just followed this simple multiplayer tutorial and it was working perfectly until I added some UI to let the user specify a port to host on. Before it was set statically in the code. Now, the server doesn’t start anymore. What’s the matter here, and how can I resolve this?
The GDScript code for my main scene looks like this:
extends Node2D
@onready var peer = ENetMultiplayerPeer.new()
@export var playerScene: PackedScene
var uiInstance
func _ready():
var uiScene = preload("res://mainMenu.tscn")
uiInstance = uiScene.instantiate()
uiInstance.connect("optionChosen", _on_option_chosen)
add_child(uiInstance)
func _on_option_chosen(option, ip, port):
match option:
"host":
peer.create_server(port)
multiplayer.multiplayer_peer = peer
multiplayer.peer_connected.connect(_add_player)
_add_player()
"join":
peer.create_client(ip, port)
multiplayer.multiplayer_peer = peer
func _add_player(id = 1):
var player = playerScene.instantiate()
player.name = str(id)
call_deferred("add_child", player)
and the code for my UI scene looks like this:
extends Control
signal optionChosen(option, ip, port)
func _on_host_pressed():
var port = int($VBoxContainer/fields/port.text)
emit_signal("optionChosen", "host", "", port)
self.visible = false
func _on_join_pressed():
var ip = $VBoxContainer/fields/ip.text
var port = int($VBoxContainer/fields/port.text)
emit_signal("optionChosen", "join", ip, port)
self.visible = false
i’m pretty new to all this, and i’d really appreciate any help you can give me!