0 votes

Hi everyone,

depending on entered numbers (coming from a simple Label) a calculation is going on within a Timer node to determine the timer duration.

    ...
    var entered_numbers = get_node(the_entered_numbers).text

    result_for_timer_duration = 3600 / float (entered_numbers)

    set_wait_time(result_for_counter_duration)
    start(result_for_counter_duration)


func _on_Timer_timeout():
    print ("timeout")

So this prints in the „rhythm“, slowly or quickly, depending on the entered numbers.

What I want is another Label to +1 on every timeout, so I added a Label as a child to the Timer node („AddUpLabel“) and after the print this line of code:

        $AddUpLabel.text += 1

which throws the error: Invalid operands 'String' and 'int' in operator '+'.

What am I missing here?

Godot version 3.3
in Engine by (365 points)

I don't really understand. Do you want to take the add-up text and increment it? Maybe try this?

$AddUpLabel.text = str(int($AddUpLabel.text) + 1)

Sorry if this isn't what you meant. Also, this implementation is kind of weird. maybe have a seperate variable you increment and set $AddUpLabel.text to that variable.

Perfect, thank you!
(Still a noob, I see what's going on when shown, but can't quite get there on my own yet...)

Please stop adding "Random beginner-question: " ... it is of no use (you are not posting a random question) and makes search for 'random' harder.

Thanks :)

You're right! I'll skip this in the future.

1 Answer

0 votes

Yes @CollyBlarge right. You have to do type conversion.

var counter = 0;
...
counter += 1
$AddUpLabel.text  = "Some Text label" + String(counter)
by (48 points)
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 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.