how change/set a variable from network

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

hi guys…
after joining 2 players in the lobby, we pause the scene tree. then we call the pause menu (the bottom code is the pause menu script). i want to sync scenes of 2 players, so when each player press the pause button, game should start. the problem is that i dont know how to send and set a variable in each scene (p1_pressed belongs to server and should be true and send it to the client and p2_pressed belongs to client and should be true and send it to the server)
when i run the game with this script, when i press pause button in server scene, in debugger p1_pressed set to “true” and p2_pressed set to “false” and when i press pause button in client scene, in debugger p1_pressed set to “false” and p2_pressed set to “true”. each scene seems send nothing to each other, how should i fix this?
Any help or guidance would be greatly appreciated :slight_smile:

p.s: this is a one on one fighting game

extends Panel

onready var waiting = get_node("Waiting")
onready var count_down = get_tree().get_root().get_node("PvP/CountDown")
onready var counter = get_tree().get_root().get_node("PvP/CountDown/Counter")
onready var counter_animation = get_tree().get_root().get_node("PvP/CountDown/CounterAnimation")
onready var counter_timer = get_tree().get_root().get_node("PvP/CountDown/CounterTimer")

var p1_pressed
var p2_pressed

func _on_Paused_pressed():
	waiting.show()
	p1_pressed = false
	p2_pressed = false
	if get_tree().is_network_server():
		p1_pressed = true
		rset("p1_pressed", true)
		after_post_pressed()
	else:
		p2_pressed = true
		rset("p2_pressed", true)
		after_post_pressed()

func after_post_pressed():
	print(p1_pressed)
	print(p2_pressed)
	if p1_pressed == true && p2_pressed == true:
		self.hide()
		count_down.show()
		counter_animation.play("CountDown")
		counter_timer.start()

func _on_CounterTimer_timeout():
	count_down.hide()
	get_tree().set_pause(false)
:bust_in_silhouette: Reply From: mdswamp

i chaned the script to this one, now it works and i can sync two players scenes :slight_smile:

extends Panel

onready var waiting = get_node("Waiting")
onready var count_down = get_tree().get_root().get_node("PvP/CountDown")
onready var counter = get_tree().get_root().get_node("PvP/CountDown/Counter")
onready var counter_animation = get_tree().get_root().get_node("PvP/CountDown/CounterAnimation")
onready var counter_timer = get_tree().get_root().get_node("PvP/CountDown/CounterTimer")

var p1_pressed
var p2_pressed

func _on_Paused_pressed():
	waiting.show()
	if get_tree().is_network_server():
		if p1_pressed:
			return
		p1_pressed = true
		post_pressed1(p1_pressed)
	else:
		if p2_pressed:
			return
		p2_pressed = true
		post_pressed2(p2_pressed)

remote func post_pressed1(pressed1):
	pressed1 = true
	p1_pressed = pressed1
	rpc("post_pressed1", pressed1)
	start_timer()
remote func post_pressed2(pressed2):
	pressed2 = true
	p2_pressed = pressed2
	rpc("post_pressed2", pressed2)
	start_timer()

remote func start_timer():
	print(p1_pressed)
	print(p2_pressed)
	if p1_pressed == true && p2_pressed == true:
		self.hide()
		count_down.show()
		counter_animation.play("CountDown")
		counter_timer.start()

func _on_CounterTimer_timeout():
	count_down.hide()
	get_tree().set_pause(false)