0 votes

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")
in Engine by (12 points)

1 Answer

+1 vote

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")
by (545 points)
edited by

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.

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

enter image description here

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.