Godot Version
4.3
Question
I found this solution to a problem i was having when syncing variables but I can’t wrap my head around why it works.
Essentially I am making a freeze tag game. Where the players have the ability to freeze other players disabling their movement. So I had these two rpcs (that are attached to a script that is the child of the main player node called TaggerManager)
var is_frozen: bool = false
...
@rpc("authority", "call_local", "reliable")
func freeze_player(freeze_state):
is_frozen = true
print("is_frozen: ", is_frozen)
# Check on server if a player can be tagged and if they can freeze their input
@rpc("any_peer", "call_local", "reliable")
func try_tag_player(taggee_id):
if multiplayer.is_server():
var tagger_id = multiplayer.get_remote_sender_id()
print("tagger ", tagger_id, " tried to tag ", taggee_id)
if potential_tags.has(tagger_id) and potential_tags[tagger_id] == taggee_id:
print("tagger ", tagger_id, " TAGGED ", taggee_id)
freeze_player.rpc_id(taggee_id, true)
...
as you can see i am setting is_frozen to true when the rpc is called. But this would not actually set the variable so the player was still able to move. Then when I set the is_frozen variable to static, it magically just worked.
But WHY does this work? Shouldn’t setting the variable to static make it so it is shared between all instances of the player class? So wouldn’t ALL players be frozen?
Thanks for taking the time to help understand this and please let me know if you need more clarification.