0 votes

Hi everyone,

It appears that this prints every frame:

func _draw():
    if previous_text != text:
        print("Text changed: ", text)

Is that what func _draw(): does? I'd only need this to print once every time the text changes. Should I use some different function entirely or is there any way to interrupt this one?
( Putting

if previous_text == text:
    return

in front doesn't work here...)

Godot version 3.3
in Engine by (435 points)

1 Answer

0 votes
Best answer

Either of the code blocks you show should short circuit the function and prevent the contained code from executing until the text changes - but only if you UPDATE the value stored in the previous_text variable. You don't show that happening, so I assume that's the issue...

Something like this should work:

var previous_text = null

func _draw():
    if previous_text != text:
        previous_text = text
        print("Text changed: ", text)
by (13,112 points)
selected by

Your solution works perfectly again.

I tried

if previous_text != text:
    previous_text = text
    print("Text changed: ", text)

with the var previous_text = ""

before, so just "" instead of null.

What a difference this makes, thank you very much!

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 webmaster@godotengine.org with your username.