label problem string to int

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

label.set_text(integer) not working

var player_top_hp=100

func _on_Button_button_up():
player_top_hp-=10
label.set_text(player_top_hp) Not Working

    "change string to integer"
:bust_in_silhouette: Reply From: Skyfrit

You need to use str() to convert integer to string.

label.set_text(str(player_top_hp))

i am use (int(playertop_hp)) not working :smiley: thanks

ibo348 | 2018-01-17 15:52

It doesn’t work because set*_*text only accept string, so you need to convert playertop_hp to string.

https://godot.readthedocs.io/en/stable/classes/class_label.html#class-label-set-text

Skyfrit | 2018-01-17 17:17

hi, how would you convert it?

Jeejus | 2020-10-25 22:55

Do you mean how to convert integer to string?

just use str() or String() to convert integer to string, Example: str(10) or String(10)

https://docs.godotengine.org/en/stable/classes/class_@gdscript.html?#class-gdscript-method-str
https://docs.godotengine.org/en/stable/classes/class_string.html?highlight=string

Skyfrit | 2020-10-26 08:47