Need help with multiplayer problems

Godot Version

4.21 stable

Question

Its my first time creating a multiplayer game so i decided to make a simple card game when i tried to make a system to make you be able to place on a placeholder the cards it only showed the card to the player that placed it i tried using RPC to solve that but it still didn’t work maybe its because i dont know how to use it i tried reading the docs but i just got even more confused

heres the code on the main game script:

func _on_area_2d_mouse_entered():
	for Card in $Cards.get_children():
		if Card.state == InMouse:
			Card.pos = 2
			#detects when the card is inside the place holder and can be placed
func _on_area_2d_mouse_exited():
	for Card in $Cards.get_children():
		if Card.state == InMouse:
			Card.pos = 1
			#detects when the card left the place holder area

func _physics_process(_delta):
	for Card in $Cards.get_children():
		if Card.pos == 2:
			rpc("show_card")

@rpc("any_peer", "call_local", "reliable")
func show_card():
	for Card in $Cards.get_children():
		if Card.pos == 2:
			$CardBase.change(Card.CardImg)
			Card.queue_free()

and heres the code inside the card placeholder:

func _ready():
	CardSize = size
#	print(CardInfo)
	$Card.texture = load(CardImg)
	$Card.scale *= CardSize/$Card.texture.get_size()
	cscale = $Card.scale

func change(img):
	$Card.texture = load(img)
	$Card.scale = cscale

im a beginner still so the code is nothing much complex

The problem is the mouse entered/exited do not happen on the peers. You will need to synchronize the card state Card.pos = 2 via a rpc or a MultiplayerSynchronizer on the card itself.

That way when the rpc is called it can find the card with the value of 2.

If you want to learn a little more about the multiplayer nodes. Check this blog post out

1 Like

Ok i will try that thank you

It didn’t work;-; i did use a multiplayer sync but nothing happend again

Can you verify on the peer that the value changed? (You can use the remote tree to look at object values). Are there any errors? Are you by chance manipulating authority?

Im not doing anything with authoritys yet
About the errors It didn’t show anything

1 Like

Did you add a replication config to the synchronizer, with the property pos?

It can be a little easier if you @export var pos

No i exported the value and used the sync property option maybe that was the problem

I did export it yea i did export it and did the same process you do to sync a player position using the multiplayer synchronizer

1 Like

Im starting to think that maybe it could be the way i make the multiplayer work because i made a simple system just for now since i didn’t even how How i would do the rest of the game

Oh, if you aren’t changing authority, and moving the mouse on a window that is a client it will not replicate back to the server.

If its the server window it should work.

That part of the code is not on the sever if im not worng


Its on the playspace spript witch is where the network part is

For simplicity i would add an rpc on the card and call it like card.set_pos.rpc(2) card.set_pos.rpc(1)

K i will do that now to see if it works

Ngl um not really sure where i should put It but i will test something rn

I need to mention something the pos in the code is not position its a variable that i made to detect when the card can be placed maybe i should have Said it earlier but yeah

so on the card i did like you said i created a func to handle the rpc call:

@rpc("any_peer","call_local","reliable")
func set_pos(Pos):
	pos = Pos

and on the sever i changed it to call the function:

func _on_area_2d_mouse_entered():
	for Card in $Cards.get_children():
		if Card.state == InMouse:
			Card.set_pos.rpc(2)
			#detects when the card is inside the place holder and can be placed
func _on_area_2d_mouse_exited():
	for Card in $Cards.get_children():
		if Card.state == InMouse:
			Card.set_pos.rpc(1)
			#detects when the card left the place holder area

but now 5 errors appeared

get_node: Node not found: “Playspace/Cards/CardBase” (relative to “/root”);
process_simplify_path: Parameter “node” is null;
get_node: Node not found: “Playspace/Cards/CardBase” (relative to “/root”);
_process_get_node: Failed to get path from RPC: Playspace/Cards/CardBase;
process_rpc: Invalid packet received. Requested node was not found.

My spagetti code attacks again

ngl im thinking about just making another system but since im not every experienced on programing i dont know how i will do that this one is just too buggy