RPC Not working

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

Does anyone see anything wrong with this code i cant seem to get it to work. The code executes on the first client but on the second or more it wont execute the register player function. Also in the below code example the indents are messed up

func _connected_ok():
     rpc("register_player", get_tree().get_network_unique_id(), my_info)

remote func register_player(id, info):
# Store the info
player_info[id] = info
# If I'm the server, let the new guy know about existing players
if get_tree().is_network_server():
	# Send my info to new player
	rpc_id(id, "register_player", 1, my_info)
	# Send the info of existing players
	for peer_id in player_info:
		rpc_id(id, "register_player", peer_id, player_info[peer_id])
		
#Update Lobby
for player_id in player_info:
	if not player_info[player_id]["name"] in $Lobby/ItemList.items: 
		$Lobby/ItemList.add_item(player_info[player_id]['name'])

How do you check if function gets called? By debugging? Maybe it’s just part of the function that is not getting called.
Since you said indents are messed up, maybe part of the code that follows #Update Lobby belongs to if statement? It shouldn’t.

By “first client” you mean server or first peer that connects to it?

hilfazer | 2018-04-23 19:41