My code is like this:
Server
var rooms: Dictionary = {}
func updateData():
for room in rooms.values():
for roomPlayer in room.players:
passRoomData.rpc_id(roomPlayer, encode(room))
Client
@rpc("any_peer")
func passRoomData(data):
var roomRes = decode(data)
RoomRes
class_name RoomRes
var roomNumber: int
var players: Dictionary = {}
var creator: int
var started := false
players is a Dictionary of int to PlayerRes
PlayerRes
class_name PlayerRes
var id: int
var playerName = ""
var color = ""
The functions I'm struggling with are encode and decode.
inst_to_dict worked fine, but couldn't help with players in RoomRes.
var_to_bytes_with_objects gives me this error: Parser Error: Class "RoomRes" hides a global script class., which I couldn't figure out how to solve.
JSON strigify method gives me <RefCounted#-9223372006035028792> which I think comes from the fact that room is a value in rooms but I couldn't solve it.
And yes, I want a class, I know I can just use dicts but I'm sure there's a better way.
Appreciate you for reading and thanks in advance