Why does my client send out the id 1?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By exuin

Here is my code

extends Node

const DEFAULT_IP := ""
const DEFAULT_PORT := 54321
const MAX_PLAYERS := 6

var players := {}
var game: Node2D

func create_server() -> void:
	var net = NetworkedMultiplayerENet.new()
	net.create_server(DEFAULT_PORT, MAX_PLAYERS)
	get_tree().network_peer = net
	get_tree().connect("network_peer_connected", self, "player_connected")
	get_tree().connect("network_peer_disconnected", self, "player_disconnected")
	print("Server created.")

func join_server() -> void:
	var net = NetworkedMultiplayerENet.new()
	net.create_client(DEFAULT_IP, DEFAULT_PORT)
	get_tree().network_peer = net
	print("Server joined.")

func player_connected(id: int) -> void:
	rpc("register_player", id)

func player_disconnected(id: int) -> void:

remote func register_player(id: int) -> void:
:bust_in_silhouette: Reply From: aengus126

I don’t know much about networking (I actually just started today) but is it possible that you are looking for the unique ID instead? that can be found with get_tree().get_network_unique_id(). Hope this helps.

network_peer_connected ( int id )

Emitted whenever this SceneTree’s network_peer connects with a new peer. ID is the peer ID of the new peer. Clients get notified when other clients connect to the same server. Upon connecting to a server, a client also receives this signal for the server (with ID being 1).

The docs say that it should be the ID of the peer, so the unique id.

exuin | 2021-12-31 03:44

:bust_in_silhouette: Reply From: exuin

Nevermind I’m dumb

I forgot to call the function that changes the id of the player to something besides the default 1