0 votes

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 gamestat.gb (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.setcargos' is not allowed on node
/root/lobby from: 496164672. Mode is 0, master is 1.
api.cpp:288 @ processrpc()

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 setcargos(idx), func supprimecargo(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 rpcid(1, "gamestate.setcargos", 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.

in Engine by (72 points)
edited by

1 Answer

+1 vote
Best answer

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 gamestate.gb, for example called trigger_set_cargothat inside executes the rpc_id.


func trigger_set_cargo(idx):
    rpc_id(1, "set_cargos", index_cargo)
by (572 points)
selected by

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.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.