+1 vote

Hello,
I make a multiplayer game on the model of multiplayer bomber.
on gamestat.gb (autoload) I have the code:

func player_cargo_port(name, idx_cargo, idx_port):
    var cargo = idx_cargo
    var port = idx_port
    rpc_id(1, "maj_cargos", cargo)
    rpc_id(1, "append_all_players", unique_id, name, cargo, port)

remotesync func maj_cargos(cargo):
    cargos[cargo][2] = true
    rpc("update_cargos", cargos)

remotesync func update_cargos(dict):
    cargos = dict

remotesync func append_all_players(id_expediteur, name, idx_cargo, idx_port):
    all_players[id_expediteur] = [name, idx_cargo, idx_port]
    rpc("update_all_players", all_players)

remotesync func update_all_players(dict):
    all_players = dict
    emit_signal("player_list_register")

This works very well for the all_players dictionary, but for the cargo dictionary declared like this on gamestat.gb:

   var cargos = {0:[load("res://images/cargo_bleu.png"), "Bleu", false], 1:[load("res://images/cargo_bordeau.png"), "Bordeau", false], 2:[load("res://images/cargo_jaune.png"), "Jaune", false], 3:[load("res://images/cargo_rouge.png"), "Rouge", false], 4:[load("res://images/cargo_vert.png"), "Vert", false], 5:[load("res://images/cargo_violet.png"), "Violet", false]}

I have a big problem, on the server I have well:
print_debug("cargos : ", cargos) from lobby.gb =>

cargos : {0:[[StreamTexture:1131], Bleu, False], 1:[[StreamTexture:1134], Bordeau, True], 2:[[StreamTexture:1137], Jaune, True], 3:[[StreamTexture:1140], Rouge, False], 4:[[StreamTexture:1143], Vert, False], 5:[[StreamTexture:1146], Violet, False]}

but on the client the texture is transformed like this:

cargos : {0:[[EncodedObjectAsID:3156], Bleu, False], 1:[[EncodedObjectAsID:3157], Bordeau, True], 2:[[EncodedObjectAsID:3158], Jaune, True], 3:[[EncodedObjectAsID:3159], Rouge, False], 4:[[EncodedObjectAsID:3160], Vert, False], 5:[[EncodedObjectAsID:3161], Violet, False]}

Thank you for your help, I'm new to Godot.

asked Dec 14, 2019 in Engine by patlol (66 points)
edited Dec 14, 2019 by patlol

2 Answers

+1 vote
Best answer

You shouldn't really pass the object it self , why not just pass the path (string) to the client then later u do loading like following

var dict = {0: "res://my_image1.png"}
var image1 = load( dict[0] )

the reason your client gets encoded objects index, is that godot doesn't transfer your server images files to the client, it assumes that the client have them, thats why it tries to find them using their index

and sure you can remotely download the images to your client using HTTP_request node but this is something different

answered Dec 14, 2019 by Xtremezero (288 points)
selected Dec 19, 2019 by patlol
0 votes

it assumes that the client have them, thats why it tries to find them using their index

But the client has them. The same image files with the same path are available at the server and the client. But nothing is displayed without generating an error message.

So I have to use a dictionary like this:

var cargos = {0:["res://images/cargo_bleu.png", "Bleu", false], ...]

And in lobby.gb, when I want to display one, use a code like :

var texture1 = load(gamestate.cargos[3][0])
get_node(ctrl_players + "/list").set_item_icon(idx, texture1)

Knowing that the client and server have image files with the same path.

Thank you for your answer

answered Dec 14, 2019 by patlol (66 points)
edited Dec 14, 2019 by patlol
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 How to use this Q&A? before posting your first questions.