|
|
|
|
Reply From: |
quijipixel |
You could do something like this:
var pos = get_visible_characters()
if dialog[page].length() > pos and dialog[page][pos] == ' ':
print("Space!!!")
You had me excited there for a quick minute… then:
Parser Error: Identifier not found: pos
Robster | 2017-08-24 00:41
Don’t forget to declare the pos
variable! If you don’t like it that much, use the more straightforward approach:
if dialog[page].length() > get_visible_characters() and dialog[page][get_visible_characters()] == ' ':
print("Space!!!")
quijipixel | 2017-08-24 00:46
Thank you.
OK so get_visible_characters()
is the current character?
It does work and I am very much appreciative. Just trying to get my head around it. I would have thought get_visible_characters()
would return an integer of how many characters their are.
Let me think out loud in public
This appears to be what’s happening:
If the length of the dialog string is greater than the length of the characters in the RichTextEdit AND the length of the dialog equals space, then print.
I am fully stumped on that one
Am I misinterpreting get_visible_characters()
?
Robster | 2017-08-24 01:08
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:
set_visible_characters(get_visible_characters()+1)
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()] == ' ':
print("Space!!!")
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 0
to length - 1
, and functions like size()
and 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 0
to get_visible_characters() - 1
. Because the strings are the same you can check if the last visible character is a space character in the dialog[page]
string.
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.
quijipixel | 2017-08-24 18:51