@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)