Topic was automatically imported from the old Question2Answer platform.
Asked By
prisius
Hello,
I am trying a project but i am facing a problem, it could be a logical problem because i am a newbie and i never faced this kind of problem. TLTR: sorry if i am a newbie
my program have these condition.
_process(delta):
function_to_run()
but i want to run it only once when a condition is met. Because i have plenty of conditions that is running to check if everything is met but i can not figure out this one.
The code your posted is no valid gdscript, but at best pseudo-code describing your idea. Therefore it’s hardly possible to help you with your specific problem.
That said, this is what you probably want to do:
var some_condition = false
func _process(delta):
if some_condition == true:
function_to_run()
func function_to_run():
# run content...
some_condition = false
Here some_condition is a global variable, defaulting to false. The _process-function is run each time a frame is drawn and checks, if that variable is true. Which of course won’t happen, unless you set it to true somewhere else, e.g. in a signal-callback. But once you did that and the next frame is drawn, function_to_run will be executed and set some_condition back to false, so the next frame it won’t be executed again. Checking some_condition again in the beginning of function_to_run is not necessary for this example, but might be done anyways to ensure that the function cannot be called accidentally, i.e. while some_condition is false.
Hi there. I have a question about this code below.:
extends TextureButton
var a = preload("res://icon.png")
var b = preload("res://ubejdat.png")
var coll=[a,b]
func _ready():
randomize()
func _process(d):
cicl()
yield(get_tree().create_timer(5),"timeout")
set_process(false)
func cicl():
for i in coll.size():
texture_normal=(coll[randi()%coll.size()])
I want to randomly iterate the TextureButton object texture_normal images which included in array var named coll. But i don’t want it iterates infinitely in _process(d) func. I used “set_process(false)”… Can i use any another method to do same without set_process(false) or in static func to have the random iteration effect like in casino 777 games, and stop iteration after some seconds for example…? Thanks in advance…