0 votes

Import the following test code into a label, then select the code and press Shift+Tab to correct the idention I did for this question, and type a lot of text in the label, with a lot of spaces, something like: A1 A1 A1 A1 A1 A1

    extends Label

    var i = 0
    var CharCount = get_text().length()
    var TimerStorage = 0
    var DelayText = 0.01#Speed of text

    func _ready():
        print("This is the char length of the text: "+str(CharCount))

    func _process(delta):
        if get_visible_characters() < CharCount:
            print("Current get_visible_character() "+str(get_visible_characters()) + " And, get_percent_visible() "+ str(get_percent_visible()))
            TimerStorage += delta

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

Your printable output is something like:

Current get_visible_character() 0 And, get_percent_visible() 0
Current get_visible_character() 1 And, get_percent_visible() 0.055556
Current get_visible_character() 2 And, get_percent_visible() 0.111111
Current get_visible_character() 3 And, get_percent_visible() 0.166667
Current get_visible_character() 4 And, get_percent_visible() 0.222222
Current get_visible_character() 5 And, get_percent_visible() 0.277778
Current get_visible_character() 6 And, get_percent_visible() 0.333333
Current get_visible_character() 7 And, get_percent_visible() 0.388889
Current get_visible_character() 8 And, get_percent_visible() 0.444444
Current get_visible_character() 9 And, get_percent_visible() 0.5
Current get_visible_character() 10 And, get_percent_visible() 0.555556
Current get_visible_character() 11 And, get_percent_visible() 0.611111
Current get_visible_character() 12 And, get_percent_visible() 0.666667
Current get_visible_character() 13 And, get_percent_visible() 0.722222
Current get_visible_character() 14 And, get_percent_visible() 0.777778
Current get_visible_character() 15 And, get_percent_visible() 0.833333
Current get_visible_character() 16 And, get_percent_visible() 0.888889
Current get_visible_character() 17 And, get_percent_visible() 0.944444
Current get_visible_character() 18 And, get_percent_visible() 1
Current get_visible_character() 19 And, get_percent_visible() 1.055556
Current get_visible_character() 20 And, get_percent_visible() 1.111111
Current get_visible_character() 21 And, get_percent_visible() 1.166667
Current get_visible_character() 22 And, get_percent_visible() 1.222222
Current get_visible_character() 23 And, get_percent_visible() 1.277778
Current get_visible_character() 24 And, get_percent_visible() 1.333333
Current get_visible_character() 25 And, get_percent_visible() 1.388889

The percent visible should not be > 1, the get_visible_character() does not take into account the space between letters. Is this intended? I don't see it specified in the documentation.

Did I stepped into a bug? o.O

My workaround was to discover how much percent a single char is based on your text:

var DiscoverPercentAddPerChar = float(0)
DiscoverPercentAddPerChar = get_percent_visible()

Because the get_percent_visible() does consider the spaces.

-Funny thing, I discovered this because I played a sound for every set_visible_characters(get_visible_characters() + 1) and it continued to play despite no more text was needed to be showed.

asked May 5 in Engine by The_Black_Chess_King (265 points)

Nevermind, it is specified it does not count spaces.

Topics related to subject:



What it looks like the get_total_character_count() is getting an upgrade/option? in Godot 4.0 to count spaces.

1 Answer

0 votes
Best answer

I completed a simple typewrited effect, and for anyone following the same issue I had, the workaround for now is by using the count("A"), which will count the amount of "A" a string letter or phrase it appears.

var SpacesToRemove = get_text().count(" ")

#Then later in my code I did:
LastCharCount = get_visibile_characters()
set_text(get_text + str(AdditionalText))
set_visible_characters(LastCharCount - AdditionalSpaces)
#So from here forward my typewriter effect can pick up, this was for additional lines in a label.

I tried with a RichTextLabel but didn't get what I wanted for this specific case. Keep in mind the same functions works differently in Label and RichTextLabel. Most of the time with a RichTextLabel you have to use yield(get_tree(), "idle_frame")

answered May 6 by The_Black_Chess_King (265 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.