Why isn't this while loop updating the label each iteration?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Soulis
:warning: Old Version Published before Godot 3 was released.

I was fooling around with the scene change example code and I can’t seem to get this while loop to update label each iteration.

extends Panel
var i = 1
func _ready():
	pass


func _on_goto_scene_pressed():
	while(i < 1000000):
    		get_node("Label").set_text(str(i))
    		i += 1
    	get_node("Label").set_text("Done")
    	
:bust_in_silhouette: Reply From: JTJonny

It seems like you are writing over the same label. Its probably updating, but to fast for you to see.

Try using a timer instead of a while statement.

or something like this:

extends Panel
var i = 0.0

func _ready():
	set_process(true)
func _process(delta):	

	if i < 1000:
		i += 1 * delta	
		get_node("Label").set_text(str(int(i)))
	
	else:
		get_node("Label").set_text("Done")

Thanks for the help. I think you were half right in that the while loop was too quick, because I don’t think the set_text methods are getting though at all. Rather one write starts and then another goes on top of it, and another until the last write finally goes though(otherwise I would see a rapid scroll of numbers).

Thanks for the help.

Soulis | 2016-06-26 22:37

If you want to test if it’s going though just use .get_text() then print().
(it is going through)

enter image description here

JTJonny | 2016-06-26 23:27