Set or get_visible_characters and set or get_percent_visible are not working

Godot Version

`Godot Engine v4.4.1.stable.mono.official[49a5bc7b6]

Question

In the godot documentation

Classe : Label
Hérite de : Control < CanvasItem < Node < Object

A control for displaying plain text.

● int visible_characters [par défaut : -1]
set_visible_characters(valeur) setter
get_visible_characters() getter

The number of characters to display. If set to -1, all characters are displayed.
This can be useful when animating the text appearing in a dialog box.


set or get_visible_characters and set or get_percent_visible are not working

getting error: Invalid call. Nonexistent function ‘get_visible_characters’ in base ‘String’

round(value) give 150.0 instead of 150


The purpose of this section of the program is to show to the player, the number
of days until his holiday. I want to create a flyers.


nbJour = round((nbJour / 86400) + 1)
nbJour = round(nbJour) # ajustement la valeur est arrondi
if nbJour > 365:
nbJour = nbJour - 365
texte = " jours avant ta fête."
texteFinal = str(nbJour) + texte # number of days before his holiday
if nbJour == 1:
texte = “Demain, c’est ta fête. Anticipation ! Anticipation !”
if nbJour == 365:
texte = “C’est ta fête, hip, hip, hip, hourra !”
$“Feu/TempsFeu”.start()
$“Feu”.visible = true
$“Feu”.play()
longueurTexte = texteFinal.length()
print(longueurTexte, " longueur du texte ", get_stack())

print (texteFinal, " texteFinal ", get_stack())


This is not working

#for i in range (0, longueurTexte):
	#texteFinal.set_visible_characters(1)
	#print(texte, "TexteFinal", get_stack())

**************************************************

TimerStorage = 0
DelayText = 0.01  #  Speed of text
visible_characters
longueurTexte.set_visible_characters()
print(longueurTexte, " longueur du texte   ", get_stack())

func _process(delta):
if texteFinal.get_visible_characters() < longueurTexte:
print(" le caractère "+str(texteFinal.get_visible_characters()) +
" Et, get_percent_visible() "+ str(texteFinal.get_percent_visible()))
TimerStorage += delta

if TimerStorage > DelayText:
	TimerStorage = 0
	texteFinal.set_visible_characters(texteFinal.get_visible_characters() + 1)

If get_percent_visible or get_visible_characters are deprecated,
please give me the correct function.

Thank you,
Michel

You’re likely referring to the visible_characters and percent_visible properties. You don’t need to call the getter and setter methods because you can get and set these properties using standard syntax.

For example, instead of:

texteFinal.set_visible_characters(texteFinal.get_visible_characters() + 1)

you can simply write:

texteFinal.visible_characters += 1

Here are your corrected codes:

for i in range (0, longueurTexte):
	texteFinal.visible_characters = 1
	print(texte, "TexteFinal", get_stack())
func _process(delta):
    if texteFinal.visible_characters < longueurTexte:
        print("Le caractère %d, percent_visible %f" % [texteFinal.visible_characters, texteFinal.percent_visible])
        TimerStorage += delta
if TimerStorage > DelayText:
	TimerStorage = 0
	texteFinal.visible_characters += 1

Also, round() returns a floating point value (with decimals). If you want an integer output, cast the result inside an int() call. Like this:

nbJour = int(round((nbJour / 86400) + 1))

Hope this helps!

Thank you for your explanation and script hint.
Now, I tried this:
print(texteFinal, " final text for the birthday “,get_stack())
156 jours avant ta fête. *** final text for the birthday ***
print(texteFinal.visible_characters, " est un INT du nombre de caractères”,get_stack())
The script stopped and I am getting this error.
Invalid access to property ‘visible_characters’ on base object of type ‘String’.
Can you explain why and suggest a better solution.
thank you,
Michel

1 Like

Your code will be easier to read if you do this:

```gdscript
code
```

That takes care of formatting and highlighting.

It looks like texteFinal is a String, which doesn’t have visible_characters as a property. That property will be on something like a RichTextLabel, which will have a .text field that is a String, but if you want to know how many characters are visible you have to ask the label, not the string; the string doesn’t know. It just holds data. It’s the label that decides how much of that data to display.

1 Like

Thank you, this gives me a good hint.