The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I (thought) had followed the instructions here:
but I can't for the life of me get the signals to work. I would like to make sure that the servers are working before I get any further in the project. So my question is how do you work with signals with an autoloaded script like this? I've only ever done signals through the godot UI.


Here's my code in case you want to see it. Beware, it's not awesome.

    extends Node

var UserIPAddress = ""
var UserPort = 31400
var PlayerCount = 4
var Nickname

var players = {}
var self_data = {name = "", position = Vector3(0,0,0)}

func _ready():
    get_tree().connect("player_connected", self, "_player_connected")
    get_tree().connect("player_disconnected", self, "_player_disconnected")
    get_tree().connect("connected_to_server", self, "_connected_ok")
    get_tree().connect("connection_failed", self, "_connected_fail")
    get_tree().connect("server_disconnected", self, "_server_disconnected")

func create_server(player_nickname): = player_nickname
    players[1] = self_data
    var peer =

func join_server(player_nickname): = player_nickname
    var peer =

func connected_to_server():
    players[get_tree().get_network_unique_id()] = self_data
    rpc('_send_player_info', get_tree().get_network_unique_id(),self_data)
    print("Successfully connected")
func player_disconnected():
    print("Player has left the lobby")

func player_connected():
    print('Player connected: ')

func connection_failed():
    print("connection failed")

func server_disconnected():
    print("Server Disconnected")
remote func _send_player_info(id,info):
    if get_tree().is_network_server():
        for peer_id in players:
            rpc_id(id, "_send_player_info", peer_id, players[peer_id])
    players[id] = info

    var new_player = load("res://Scenes/Player.tscn").instance() = str(id)
    new_player.init(, info.position, true)
remote func kickPlayer():
in Engine by (93 points)

1 Answer

+2 votes

The names of the functions are wrong.
If you wrote

   get_tree().connect("connected_to_server", self, "_connected_ok")

then you name the func as

func _connected_ok():

and not

func connected_to_server():
by (176 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.