No information circulating between the client and the server

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

I’m starting an unpretentious tycoon-like game: I start with the beginning of the game, the registration of the players (based on multipleyrs bomber: with autolad and lobby) all this is going well the client and server are ok. Then the players have to choose a cargo ship and a port of departure (it’s a sea tycoon) and there is no way to tell the other players that this cargo ship and this port are required, so they are no longer available.

But there is no information circulating between the cli and the serv. I confess that I’m new to godot, and I have trouble with the network logic used by godot.

extract code (autoload) :

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

remotesync func set_cargos(idx):
    cargos[idx][2] = true
    emit_signal("cargos_changed", idx)  # => lobby.supprime_cargo(index)

func _on_ItemList_item_selected(index):
    # cargo
    index_cargo = index

func _on_id_pressed(idx):
    # port
    index_port = idx

func _on_OkCargo_pressed():
    if index_cargo == 999 or index_port == 999:
        get_node(ctrl_error_cargo).text = "Vous devez sélectionner un cargo et un port"
        # jusqu'ici tout va bien index_cargo et index_port sont ok
        if is_network_master():
            rpc_id(1, "gamestate.set_cargos", index_cargo)

func supprime_cargo(idx):
    get_node(ctrl_cargo + "/ChoixCargo/ItemList").set_item_disabled(idx, true)

A debugger error is displayed: when the client chooses its cargo, the debugger on the server sends:

E 0:00:34:0885 RPC ‘gamestate.set_cargos’ is not allowed on node
/root/lobby from: 496164672. Mode is 0, master is 1.
core/io/multiplayer_api.cpp:288 @ _process_rpc()

No error is reported on the client in any case.

Locally on the server, the cargo dictionary is up to date when the server chooses its cargo but the client doesn’t receive anything, i.e. cargo is not up to date in the client and prints placed in remotesync func set_cargos(idx), func supprime_cargo(idx) are not displayed with the client code.

When the client chooses his cargo the only printout that appears is the one placed in func delete_cargo(idx) after rpc_id(1, “gamestate.set_cargos”, cargo_index) Dictionnary cargos no update in the code executed by the client.

No items are disabled except for the server’s item for its own choice and at home only.

:bust_in_silhouette: Reply From: tastyshrimp

Your problem is probably related to the rpc_id(1, "gamestate.set_cargos", index_cargo) call. That is because you are using the function wrong, looking at the definition in the docs, rpc_id(<peer_id>,”function_name”, <optional_args>). This means rpc_id is a method of the Node that requests the execution of a function on a defined peer. You cannot pass class.function.

One way to solve this is to make a method on the, for example called trigger_set_cargothat inside executes the rpc_id.

func trigger_set_cargo(idx):
    rpc_id(1, "set_cargos", index_cargo)

Thank you very much,

it works as long as you put

rpc("set_cargos", index_cargo)

instead of

rpc_id(1, "set_cargos", index_cargo)

I have no idea why, but it does what I wanted it to do.

patlol | 2019-12-20 19:18