- Home /
The question is answered, right answer was accepted
Indexes behaving weirdly
so basically my dialogue and formatting system was totally complete, then a weird bug appeared that caused the first formatting action in my sentence to be carried over to all the other actions (like the colour and bold etc.)....i sat to debug this and found out that the format index was somehow stuck on the value it first gained causing this bug...so i moved it out to the beginning of the foreach loop but the problem persisted....i created another variable that should hold the exact same value as the first.....but to my surprise, while the first one was still stuck on a single value, the new test variable was displaying some really weird indexes.....after a few ctrl + p(s) without making any change the indexes synced but both adopted the weird behaviour of the later.....
foreach(char letter in letters)
{
int formatindex = Array.FindIndex(letters, letters => letters == letter);
int indexier = Array.FindIndex(letters, letters => letters == letter);
Debug.Log(formatindex);
foreach(FormatList letter1 in chars)
{
int letterindex = Array.FindIndex(chars, chars => chars == letter1);
reversechars[reversechars.Length - letterindex - 1] = letter1;
}
if(letter == formatchar)
{
if(!format)
{
format = true;
basetext = maintext.text;
storestring = "";
CheckChar(letters[formatindex + 1]);
}
else
{
format = false;
basetext = "";
storestring = "";
foreach(FormatList letter1 in chars)
{
letter1.charactive = false;
}
}
}
else if(CheckSkip(letter))
{
continue;
}
else if(format)
{
maintext.text = basetext;
storestring += letter;
foreach(FormatList letter1 in chars)
{
if(letter1.charactive)
{
maintext.text += letter1.begintag;
}
}
maintext.text += storestring;
foreach(FormatList letter1 in reversechars)
{
if(letter1.charactive)
{
maintext.text += letter1.endtag;
}
}
yield return new WaitForSeconds(speed * speedfactor);
source.Play();
}
else
{
storestring = "";
basetext = "";
maintext.text += letter;
yield return new WaitForSeconds(speed * speedfactor);
source.Play();
}
}
the Array.FindIndex() function actually works perfect in most of my scripts and yields the correct result the first few times it's called in this one too....i have no idea why this is occuring please help...here's a video displaying the weird index behaviour
not sure, indexes may be out of order in foreach, try using a for loop.
i dunno man, the words are typing out in the correct order, but ill check with the for loop
that fixed it, thanks buddy....do you have any idea why this problem happened with foreach loops?
also can you convert this into this answer so that i can accept it?