Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | genete | |
Old Version | Published before Godot 3 was released. |
I want that two scripts of two different nodes executes one conditional action at one fixed interval synchronized.
Also I want that any of both can be activated or not to perform the action. But when it is activated it must be in sync wit the other.
This is the code I have:
extends Node2D
const INTERVAL=0.25
var time=0
var check=true
var active=true
func _ready():
set_fixed_process(true)
activate(false)
pass
func _fixed_process(delta):
time=time+delta
if not active: return
var rest=int(time/INTERVAL)
if(rest%2 and check):
var zero=get_child(0)
var one=get_child(1)
var two=get_child(2)
if zero.is_hidden(): zero.show()
else: zero.hide()
if one.is_hidden(): one.show()
else: one.hide()
if two.is_hidden(): two.show()
else: two.hide()
check=false
if(not rest%2):
check=true
func activate(a):
active=a
get_child(0).show()
get_child(1).hide()
get_child(2).hide()
But doesn’t work. Once one of them is de-activated and re-activated again it gets out of sync.