Godot: Remove the obligation to convert a text to string to put it in label.text

Created on 16 Apr 2019  路  1Comment  路  Source: godotengine/godot

Godot version:
3.2 dev

OS/device including version:
Windows 10 x64 / NVIDIA GeForce GTX 1060 6GB / Intel Core i7 4790K

Issue description:
A very boring and unnecessary thing is Label.text does not accept any number without first being converted to a string:

$Label.text = node.translation

will give an error Invalid set index 'text' (on base: 'Label') with value of type 'Vector3'.

So I have always to put an str():

$Label.text = str(node.translation)
discussion enhancement gdscript

Most helpful comment

I don't think that's feasible without changing the property to be of Variant type, which has branching implications (complexifies inspector, looses auto-completion...).
Coercion is not feasible either because prone to error in other areas where magical string auto-conversion could hide an error.
It's also just one occurrence of a text property, the same could be said of RichTextLabel and any function argument taking text... I don't think it's worth it doing special cases for that compared to casting properly with str.

>All comments

I don't think that's feasible without changing the property to be of Variant type, which has branching implications (complexifies inspector, looses auto-completion...).
Coercion is not feasible either because prone to error in other areas where magical string auto-conversion could hide an error.
It's also just one occurrence of a text property, the same could be said of RichTextLabel and any function argument taking text... I don't think it's worth it doing special cases for that compared to casting properly with str.

Was this page helpful?
0 / 5 - 0 ratings