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():
set_visible_characters(0)
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)
set_visible_characters(0)
set_visible_characters(1)
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.