Here's the situation.
I have an action "Dialogue:Play Speech" with the following text:
[cam:FaceCam][mood:surprized]Who?
Ataruamterhemutranu?
[mood:normal]Of course not.A little explanation about the tags. Tag [cam:something] finds the camera "something" and switches to it, while [mood:something] simply changes expression to something. Does exactly the same that [expression:something], only it is faster to type "mood" than "expression].
When the engine gets to this action my little dude speaks an empty line, and the debugger spits out long list of the following error:
ArgumentOutOfRangeException: startIndex + length > this.length
Parameter name: length
System.String.Substring (Int32 startIndex, Int32 length) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/String.cs:356)
AC.Speech.UpdateDisplay () (at Assets/AdventureCreator/Scripts/Speech/Speech.cs:460)
AC.Dialog._LateUpdate () (at Assets/AdventureCreator/Scripts/Speech/Dialog.cs:79)
AC.StateHandler.LateUpdate () (at Assets/AdventureCreator/Scripts/Game engine/StateHandler.cs:451)
So it seems the error is somewhere deep in the AC speech system.
The error seems to appear only when I use custom tags in several lines of text. If there is only one line, there is never a problem.
However, a speech action with following text (two lines), does not throw out exception:
[eyes:down]I'm wrong.
[eyes:straight]It was the cat.
Also, when I split the first example into two separate actions, there is no error, everything works as it supposed to.
Settings in the Speech Manager are as follow:
Treat carriage returns asa separate speech lines: true
Subtitles can be skipped: true
Can skup with mouse clicks: true
Retain subtitle text buffer once line has ended: true
Everything else is set to false. My AC version is 1.65.0.
Comments
Also I have a little update, which makes things even more confusing. The problem might not be with multi-line texts after all.
This single line of text also throws the exception:
"[cam:TaxCam][mood:surprized]What?!" -> exception
However this line of text works fine!
"[mood:surprized][cam:TaxCam]What?!" -> no problem
And here goes the best part: the function I attach (for tests) to AC.EventManager.OnSpeechToken += OnSpeechToken" looks like that:
}
It does nothing! But there is still an exception. So if I do nothing and then nothing, it is ok. But when I switch the order and first do nothing and then nothing, we have an exception.
Ok, if this doesn't sound crazy, I don't know what does.
Please help. I'm afraid of developing my game now. I think there might be dark magic involved.
Does that resolve it?
I added the following text in line 460 in Speech.cs
Debug.Log ("Full: " + log.fullText + ", Index: " + speechGaps[gapIndex].characterIndex);
When the game got to the speech with this text:
"[cam:TaxCam][mood:surprized]What?!"
Here's what the debug said:
and so on.
What I don't understand is why it has worked sometimes.
I'm sure you figured it out by now, line 460 says:
displayText = log.fullText.Substring (0, speechGaps[gapIndex].characterIndex);
And it is supposed to set displayText to, I believe, text ready to be displayed. And it would, if the log.fullText contained the full, original text, with all those custom tags and all. But it contains already the text to display as far as I checked. And the speechGaps[gapIndex].characterIndex contains the index meant for the original text.
I guess it's easy to see now why this bug survived so long. It was really hard to detect and reproduce: someone would have use more than one custom tag in the speach, but also the text to say had to be shorter than the first tag. Only then the index would go out of range.
So the question is how to fix it?
I'm not sure, but at this point in code log.fullText seems to be already processed and ready to display.
So, Chris, can I replace the line 460:
displayText = log.fullText.Substring (0, speechGaps[gapIndex].characterIndex);
with:
displayText = log.fullText ?
Will it break something?
I test it and it seems to work fine, the exception is gone, tags work, text looks exactly as expected. But since I don't understand fully this part of the code, I can't be really sure.
So there is a conversation on the start of the scene. Both characters try to speak and then generate exceptions.
Won't happen again.
I'll leave it with you then and wait for the patch.
I rely heavily on custom tags, as it saves lots of time, so I'll be waiting happily for 1.66.
And I really admire the amount of work you put into the Adventure Creator. It saves us, game developers, unbelievable amount of time.