Hey
So im working on a RPG-Ish text box, where the text is displayed trough a typewritter effect ( every second a character / letter from the string is added to the displayed message on the screen ). Since my messages go off-screen im trying to set up word wrapping for it, i have something rudimentary working alredy but the result is inconsistent
I Have a function called UpdateTextWrap where i "figure out " the character index at which i should add a new line, Then once the current message on the screen reaches that index it adds the new line and calls the function again so it updates the index
MessageCharacters is an string array that has one elemenent per character in the string that contained the dialogue (using GetCharacterArrayFromString)
Here is the code im using
void UGalileaDialogueW::UpdateTextWrap()
{
int32 wordPosition = 0;
int32 length = 0;
for (int32 iw = LoopFrom; iw < MessageCharacters.Num(); iw++)
{
wordPosition++;
// if a character, start counting
if (MessageCharacters[iw] != " ")
{
length++;
}
//if we hit an space then stop counting
else
{
length = 0;
}
// if the length plus our position goes beyond the line end, then wrap where the word began
if (length + wordPosition > lineEnd)
{
//grab the position from the index, then remove the length from it so we go back the amount of
//characters the word had
WrapAt = iw - length;
LoopFrom = iw;
break;
}
}
}
Here is the snippet from where i update the dialogue each tick and call the wrap text function when the index matches
void UGalileaDialogueW::UpdateDialogue()
{
// if our current index matches the wrap one then do so
if (CurMessageIdx == WrapAt)
{
space = 0;
line++;
WrapAt = 0;
// call the function again
UpdateTextWrap();
}
// if our current space goes beyond the line then add a new one
if (space > lineEnd)
{
space = 0;
line++;
}
The function works correctly when called “once”, It updates the wrap at text index perfectly ( which is shown as the 48 in the screenshot, thats the character position at which it will wrap ). However once i call the function a second time, the index is NOT updated it remains at the same value
Any help is certainly appreciated!