I think you are missing something here.
get_visible_characters() doesn't return the length of the characters. It returns the length of the characters that are visible. This is important! when you run the code, the function
set_visible_characters(0) is making the
RichTextLabel node show from character 0 to character 0 as visible. This means that even though the
RichTextLabel node has the full string, it will show nothing. Now, everytime the timer is activated, it will increase the visible character length like this:
You are increasing the range of visible characters from 0 to n - 1 each time the timer activates. So, keeping this in mind I'll explain the code that I did:
if dialog[page].length() > get_visible_characters() and dialog[page][get_visible_characters()] == ' ':
The If statement here has 2 parts, one that checks that the visible characters quantity in the
RichTextLabel isn't bigger that the dialogs string. Now, if you remove that part of the code and run it, you'll notice that Godot breaks when the text is completaly shown. This is because the visible characters don't represent the lenght of the dialog string, hence the value in the function might be bigger than the real size of that string, thus breaking in runtime.
So the first part of the if statement translates to If the current amount of characters visible in the
RichTextLabel is lower than the length of the
dialog[page] string. This prevents Godot from breaking when the text is finished appearing because string and array positions are accessed from
length - 1, and functions like
get_visible_characters() return the length value, not
length - 1.
The second part of the if statement just checks that the last character of the visible characters in the
RichTextLabel is a space using the dialog string. To better understand this just remember that the
RichTextLabel has his own copy of the string, and that is showing characters in a range from
get_visible_characters() - 1. Because the strings are the same you can check if the last visible character is a space character in the
So the second part of the if statement translates to: If the last shown character in the
RichTextLabel equals a space character
I think I wrote to much, tell me if it makes sense.