hi guys... i want to pause the game before scenes of 2 players load completely. but thats not a problem, problem begins when i want to unpause the game. i created a pause menu for this, changed its mode to "process" (mode of countdown node is process too) and wrote this code in pause menu:

extends Panel

onready var waiting = get_node("Waiting")

# labels and tween for showing countdown (3,2,1)
onready var count_down = get_tree().get_root().get_node("PvP/CountDown")
onready var three = get_tree().get_root().get_node("PvP/CountDown/3")
onready var two = get_tree().get_root().get_node("PvP/CountDown/2")
onready var one = get_tree().get_root().get_node("PvP/CountDown/1")
onready var t3 = get_tree().get_root().get_node("PvP/CountDown/T3")
onready var t2 = get_tree().get_root().get_node("PvP/CountDown/T2")
onready var t1 = get_tree().get_root().get_node("PvP/CountDown/T1")

var p1 #(set this one to "false" in lobby)
var p2 #(set this one to "false" in lobby)

func _ready():
	t3.interpolate_property(three, "transform/scale", three.rect_scale, Vector2(2, 2), 1,
                                                                 Tween.TRANS_QUAD, Tween.EASE_OUT)
	t2.interpolate_property(two, "transform/scale", two.rect_scale, Vector2(2, 2), 1,
                                                                 Tween.TRANS_QUAD, Tween.EASE_OUT)
	t1.interpolate_property(one, "transform/scale", one.rect_scale, Vector2(2, 2), 1,
                                                                 Tween.TRANS_QUAD, Tween.EASE_OUT)
func _on_Paused_pressed():
	waiting.show() # show some label
	post_pressed(p1,p2)

# i think problem is in this function, because variables are not being sent
func post_pressed(p1, p2):
	if get_tree().is_network_server():
		p1 = true
		rset("p1", true)
	else:
		p2 = true
		rset("p2", true)
	if p1 == true && p2 == true:
		self.hide()  # hiding the pause menu
		count_down.show() # just made a visual countdown like ("3, 2, 1")
		three.show() # show label
		t3.start() # start tween for showing the countdown

func _on_T3_tween_completed(object, key):
	three.queue_free()
	three.hide()
	two.show()
	t2.start()

func _on_T2_tween_completed(object, key):
	two.queue_free()
	two.hide()
	one.show()
	t1.start()

func _on_T1_tween_completed(object, key):
	one.queue_free()
	one.hide()
	count_down.hide()
	get_tree().set_pause(false) # this code does not work (actually countdown does not begin)

it seems variables (p1,p2) are not being sent, so game doesnt resume, what should i do now?

Any help would be greatly appreciated :)

I would suggest adding some print statements before the rset function calls to make sure rset is being called (or not). Perhaps add a line printing get_tree().is_network_server to make sure that it is returning true when it is the server, and false when it is the client.

Other than that, it's hard to say at first glance. Are you sure that _on_Paused_pressed and post_pressed are being called?

Also, since the arguments in the post_pressed function share the same name as the class variables p1 and p2, it may be that the function is overriding/conflicting due to the shared names. I would suggest renaming the variables you are passing in to the pst_pressed function to something like p1_arg and p2_arg, or something similar, to eliminate any potential same name variable conflicts.

hi @TwistedTwigleg

if i change post_pressed function like this:

remote func post_pressed(p1, p2):
    if get_tree().is_network_server():
        p1 = true
    else:
        p2 = true
    rpc("post_pressed",p1, p2)
    if p1 == true && p2 == true:
        self.hide()
        count_down.show()
        t3.start()

everything works, just there is a little problem, no matter which player press the pause button first, countdown begins to start and then game starts. can these changes answer your questions about functions calling and variables conflicts?

@mdswamp said: hi @TwistedTwigleg

if i change post_pressed function like this:

remote func post_pressed(p1, p2):
    if get_tree().is_network_server():
        p1 = true
    else:
        p2 = true
    rpc("post_pressed",p1, p2)
    if p1 == true && p2 == true:
        self.hide()
        count_down.show()
        t3.start()

everything works, just there is a little problem, no matter which player press the pause button first, countdown begins to start and then game starts. can these changes answer your questions about functions calling and variables conflicts?

I think the reason you are getting a problem here is two fold. One problem is because you are using rpc, which will call the post_pressed function on the other connection. This means the two functions will continue to call each other back and forth forever, since each time the post_pressed function is called, it uses rpc to call the other connection, which will then use rpc to call the initial connection, and so on and so forth.

The other problem is that you are setting p1 or p2 to true, and then calling post_pressed. This will set both p1 and p2 to true when the _on_Pause_pressed function is called, since post_pressed calls itself on each function (making the infinite loop I mentioned earlier).

I would try the following code (after making a backup of your code so you do now lose your work. Also, I have not tested this code):

extends Panel
onready var waiting = get_node("Waiting")
# labels and tween for showing countdown (3,2,1)
onready var count_down = get_tree().get_root().get_node("PvP/CountDown")
onready var three = get_tree().get_root().get_node("PvP/CountDown/3")
onready var two = get_tree().get_root().get_node("PvP/CountDown/2")
onready var one = get_tree().get_root().get_node("PvP/CountDown/1")
onready var t3 = get_tree().get_root().get_node("PvP/CountDown/T3")
onready var t2 = get_tree().get_root().get_node("PvP/CountDown/T2")
onready var t1 = get_tree().get_root().get_node("PvP/CountDown/T1")
var p1 #(set this one to "false" in lobby)
var p2 #(set this one to "false" in lobby)
func _ready():
    t3.interpolate_property(three, "transform/scale", three.rect_scale, Vector2(2, 2), 1,
                                                                 Tween.TRANS_QUAD, Tween.EASE_OUT)
    t2.interpolate_property(two, "transform/scale", two.rect_scale, Vector2(2, 2), 1,
                                                                 Tween.TRANS_QUAD, Tween.EASE_OUT)
    t1.interpolate_property(one, "transform/scale", one.rect_scale, Vector2(2, 2), 1,
                                                                 Tween.TRANS_QUAD, Tween.EASE_OUT)
func _on_Paused_pressed():
    waiting.show()
    post_pressed()
func post_pressed():
    if p1 == false && p2 == false:
        if get_tree().is_network_server():
            p1 = true
            rset("p1", true)
        else:
            p2 = true
            rset("p2", true)
    elif p1 == true && p2 == true:
        start_timer() # Start the timer on the local machine
        rpc("start_timer") # Start the timer on the connect machine(s)
remote func start_timer():
        self.hide()  # hiding the pause menu
        count_down.show() # just made a visual countdown like ("3, 2, 1")
        three.show() # show label
        t3.start() # start tween for showing the countdown
func _on_T3_tween_completed(object, key):
    three.queue_free()
    three.hide()
    two.show()
    t2.start()
func _on_T2_tween_completed(object, key):
    two.queue_free()
    two.hide()
    one.show()
    t1.start()
func _on_T1_tween_completed(object, key):
    one.queue_free()
    one.hide()
    count_down.hide()
    get_tree().set_pause(false)

hi @TwistedTwigleg

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()
	post_pressed()

func post_pressed():
	if p1_pressed == false && p2_pressed == false:
		if get_tree().is_network_server():
			p1_pressed = true
			rset("p1_pressed", true)
		else:
			p2_pressed = true
			rset("p2_pressed", true)
	elif p1_pressed == true && p2_pressed == true:
		start_timer()
		rpc("start_timer")
	print(p1_pressed)
	print(p2_pressed)

remote func start_timer():

	self.hide()
	count_down.show()
	counter_animation.play("CountDown")
	counter_timer.start()

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

(i removed tween codes for now and changed p1, p2 to p1_pressed and p2_pressed as you mentioned before)

i put two print command in post_pressed function, their outputs are null, i dont know why, so post_pressed sends nothing to start_timer function, its weird

after changing the script zillion times, finally it works,... this is what it become: :)

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)

just i have a question @TwistedTwigleg , in remote func start_timer() i put two print commands, when i follow debugger of both server and client, theyre printing output continuously. does it hurt the performance, can i write something in script to avoid these computations after i reached my result?

@mdswamp said: after changing the script zillion times, finally it works,... this is what it become: :)

(TwistedTwigleg: I removed the code to shorten the quote)

just i have a question @TwistedTwigleg , in remote func start_timer() i put two print commands, when i follow debugger of both server and client, theyre printing output continuously. does it hurt the performance, can i write something in script to avoid these computations after i reached my result?

I'm glad you found a solution to the problem! :smile:

As for the continuous printing, it could hurt performance. Looking at the code, the problem is that you have a continuous loop in post_pressed1 and post_pressed2.

The problem is that post_pressed1 will always call rpc("post_pressed1", pressed1), which will call post_pressed1 on the computer that initially called the function. Then the computer that initially called the function will go through post_pressed1, will call rpc("post_pressed1", pressed1), which will cause the other connects to go through post_pressed1 and call rpc("post_pressed1", pressed1), making a infinite loop.

You should be able to work around this by changing post_pressed1 and post_pressed2 to the following:

remote func post_pressed1(pressed1):
	# If p1_pressed is already set, then ignore
	# This will break the infinite loop because it is not calling "rpc("post_pressed1", pressed1)"
	# when p1_pressed has already been set on this computer.
	if (p1_pressed == true):
		return;
	pressed1 = true
	p1_pressed = pressed1
	rpc("post_pressed1", pressed1)
	start_timer()

remote func post_pressed2(pressed2):
	# If p2_pressed is already set, then ignore
	# This will break the infinite loop because it is not calling "rpc("post_pressed2", pressed2)"
	# when p2_pressed has already been set on this computer.
	if (p2_pressed == true):
		return;
	pressed2 = true
	p2_pressed = pressed2
	rpc("post_pressed2", pressed2)
	start_timer()

thanks, really thanks @TwistedTwigleg ... actually i had a problem in animation player which this bloody loop was the cause. it didn't let animation play completely and forced it to freeze on first frame. now it works perfectly :) so i put my final script, might someone want to do something like this:

thanks again Twisted... :)

extends Panel ### scene_tree has paused, this is the pause menu which in process mode...

onready var first_panel = get_node("FisrtPanel")
onready var waiting = get_node("FisrtPanel/Waiting")
onready var second_panel = get_node("SecondPanel")
onready var counter = get_node("SecondPanel/Counter")
onready var counter_animation = get_node("SecondPanel/CAnimation")
onready var counter_timer = get_node("SecondPanel/CTimer")

var p1_pressed
var p2_pressed

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

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

remote func start_timer():
	if p1_pressed == true && p2_pressed == true:
		first_panel.hide()       ### pause panel
		second_panel.show()         ### counter panel
		counter_animation.play("CountDown")        ### countdown animation (3,2,1)
		counter_timer.start()

func _on_CTimer_timeout():
	second_panel.hide()
	self.hide()
	get_tree().set_pause(false)

I’m glad you figured it out, and kudos for posting the solution for others! I’m not sure how much help I provided, but it was my pleasure :smile:

4 years later