What you need is serialization of data. Ive asked on this forums half a year or more ago, and i think with godot 4.3 or 4.2 they updated the serialization of data so that it is easy to pass data to other multiplayer players.
You could also do it with multiplayer synchronizer. I havent played much with it but some tests i did were successfull.
With serialization i was successfull (project is now broken):
var bytes = var_to_bytes_with_objects(GameManager.player_list) # var player_list: Dictionary
add_local_players.rpc_id(id,bytes)
and then
@rpc
func add_local_players(player_list_bytes):
var player_list = bytes_to_var_with_objects(player_list_bytes)
for id in player_list:
var player_obj = player_list[id]
add_player(player_obj.id,player_obj.name)
pass
func create_player(_id, _name):
var new_player_data:PlayerData = PlayerData.new()
new_player_data.id=_id
new_player_data.player_name=_name
new_player_data.score = 0.0
if multiplayer.is_server():
new_player_data.is_server=true
GameManager.player_list[_id]=new_player_data
PlayerData
extends Resource
class_name PlayerData
var id: int
var player_name:String
var is_server:bool
var score: float
Cant post minimal project because its broken.. need time to investigate and fix it but am lazy.. 😃
YOu can send simple strings without serialization using rpc's. If you want lists or heavy data then you need to serialize into bytes.
Here i was exploring: https://godotforums.org/d/40153-help-with-byteobject-conversion-sent-over-rpc/4