- Home /
After Refactoring, Sudden Slew of Nonsensical Errors
After I refactored the name of one of my files (GameManager), other errors in another file started appearing, and refuse to go away. This segment of code was working fine before, but now Unity is giving me errors...
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text;
using System.Xml;
using System.Collections.Generic;
public class TextCreepScript : Singleton<TextCreepScript> {
public Script script;
public float timePerChar;
public float periodPauseTime;
public float ellipsisFactor;
public float commaPauseTime;
public float returnPauseTime;
public float shortPauseTime;
private Text dialogueBox;
private AudioSource source;
public AudioClip[] clips;
private StringBuilder stringBuilder;
void Start() {
script = GetScriptFromXML(Application.loadedLevelName);
}
public IEnumerator PreGameText() {
StartCoroutine(GameManager.fadeIn(DialogueGroup.Instance.GetComponent<CanvasGroup>(), 1e10f));
dialogueBox = GetComponent<Text>();
source = GetComponent<AudioSource>();
Session session = script.sessions[0];
yield return StartCoroutine(UpdateText(session));
StartCoroutine(GameManager.fadeOut(DialogueGroup.Instance.GetComponent<CanvasGroup>(), GameManager.Instance.opacPerFrame));
}
public IEnumerator InGameText() {
List<Session> inGameSessions = script.sessions.GetRange(1, script.sessions.Count - 1);
foreach (Session session in inGameSessions) {
yield return new WaitForSeconds(session.startTime);
StartCoroutine(GameManager.fadeOut(DialogueGroup.Instance.GetComponent<CanvasGroup>(), GameManager.Instance.opacPerFrame * 4));
yield return StartCoroutine(UpdateText(session));
StartCoroutine(GameManager.fadeOut(DialogueGroup.Instance.GetComponent<CanvasGroup>(), GameManager.Instance.opacPerFrame * 4));
}
}
public IEnumerator UpdateText(Session session) {
source.clip = session.clip;
source.Play();
string trueString = session.text;
dialogueBox.text = "";
int charsShown = 0;
int totalChars = trueString.Length;
stringBuilder = new StringBuilder();
while (charsShown < totalChars) {
if (Input.GetKey("s")) {
source.Stop();
break;
}
stringBuilder.Append(trueString[charsShown]);
if (charsShown > 0 && (trueString[charsShown-1] == '.' || trueString[charsShown-1] == '!')) {
yield return new WaitForSeconds(periodPauseTime);
} else if (charsShown > 0 && trueString[charsShown-1] == ',') {
yield return new WaitForSeconds(commaPauseTime);
} else if (charsShown > 0 && trueString[charsShown-1] == '…') {
yield return new WaitForSeconds(periodPauseTime * ellipsisFactor);
} else if (charsShown > 0 && trueString[charsShown-1] == '\n') {
yield return new WaitForSeconds(returnPauseTime);
stringBuilder.Length = 0; // "clears" the stringBuilder
stringBuilder.Append(trueString[charsShown].ToString());
charsShown++;
dialogueBox.text = stringBuilder.ToString();
continue;
} else if (charsShown > 0 && trueString[charsShown-1] == ' ') {
charsShown++;
dialogueBox.text = stringBuilder.ToString();
continue;
} else if (charsShown > 0 && trueString[charsShown-1] == '~') {
print(stringBuilder.Length.ToString());
print((charsShown-1).ToString());
int endIndex = stringBuilder.Length - 2;
stringBuilder.Replace('~', '', endIndex, 1); // zero-width space in 2nd pair of single quotes
dialogueBox.text = stringBuilder.ToString();
charsShown++;
yield return new WaitForSeconds(shortPauseTime);
continue;
} else {
yield return new WaitForSeconds(timePerChar * session.scale);
}
charsShown++;
dialogueBox.text = stringBuilder.ToString();
}
}
Script GetScriptFromXML(string fileName) {
TextAsset tAsset = (TextAsset) Resources.Load(fileName, typeof(TextAsset));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(tAsset.text);
Script s = new Script();
foreach (XmlElement node in xmlDoc.SelectNodes("sessionCollection/session")) {
s.sessions.Add(new Session(node.InnerText, float.Parse(node.GetAttribute("time")), float.Parse(node.GetAttribute("scale"))));
}
// Attach audio clips to each session
for (int i=0; i<s.sessions.Count; i++) {
Session tempSession = s.sessions[i];
tempSession.clip = clips[i];
s.sessions[i] = tempSession;
}
return s;
}
public class Script {
public List<Session> sessions;
public Script() {
this.sessions = new List<Session>();
}
}
public struct Session {
public string text;
public float startTime;
public float scale;
public AudioClip clip;
public Session(string t, float sT, float scl) {
this.text = t;
this.startTime = sT;
this.scale = scl;
this.clip = null;
}
}
}
I now have the following errors, many of which reference rows and columns that lack any code at all (whitespace or otherwise).
Assets/Scripts/TextCreepScript.cs(70,84): error CS1012: Too many characters in character literal
Assets/Scripts/TextCreepScript.cs(70,86): error CS1525: Unexpected symbol `<internal>'
Assets/Scripts/TextCreepScript.cs(68,32): warning CS0642: Possible mistaken empty statement
Assets/Scripts/TextCreepScript.cs(72,30): error CS1525: Unexpected symbol `else'
Assets/Scripts/TextCreepScript.cs(79,30): error CS1519: Unexpected symbol `else' in class, struct, or interface member declaration
Assets/Scripts/TextCreepScript.cs(79,47): error CS1519: Unexpected symbol `>' in class, struct, or interface member declaration
Assets/Scripts/TextCreepScript.cs(79,54): error CS0178: Invalid rank specifier: expected `,' or `]'
Assets/Scripts/TextCreepScript.cs(79,80): error CS1519: Unexpected symbol `==' in class, struct, or interface member declaration
Assets/Scripts/TextCreepScript.cs(80,44): error CS1519: Unexpected symbol `++' in class, struct, or interface member declaration
Assets/Scripts/TextCreepScript.cs(81,50): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration
Assets/Scripts/TextCreepScript.cs(81,74): error CS1519: Unexpected symbol `(' in class, struct, or interface member declaration
Assets/Scripts/TextCreepScript.cs(83,30): error CS8025: Parsing error
Any help would be greatly appreciated.
I copied the script over Visual Studio 2013 and it seems fine over here. Those kind of errors you can get from the C# parser when you have wrong syntax, but as i said your script does not have any problems over here.
The row numbers and error content match your script if one assumes the first error comes from the "ellipsis" char '...'
$$anonymous$$aybe $$anonymous$$ono doesn't handle that symbol correctly. $$anonymous$$aybe you can change that check to not use the character literal.
sysameca: Yea, $$anonymous$$onoDevelop isn't detecting any errors, only Unity.
Nose$$anonymous$$ills: Through some tinkering, I've found that you are correct—that Unity is taking issue with the '…' char (and possibly the zero-width-space as well). When I run print("…") and print("…"[0]), Unity simply prints "???" and "?", which is really quite interesting, because this code was working fine before, including the ellipses. Additionally, the zero-width-space was originally printing fine in-game, but now is rendered as "?", despite no changes other than the refactoring.
Answer by pixatlazaki · Dec 30, 2014 at 11:02 AM
Found my own solution... I feel a bit silly now for asking...
Replace the '…' and zero-width-space for their unicode IDs, i.e. '\u2026'
and '\u200b'
respectively.
Not sure why '…' was working before, but oh well.
I saw that (it was the only thing I looked at.) It looked like 3 dots, but copy-paste said it was one character, which I assumed was a badly rendered underscore.
I think it was stored as unicode, originally. Then the refactor wrote it out, which would usually be the right thing to do.
Your answer
Follow this Question
Related Questions
Refactoring Code 2 Answers
Why do I receive the message "Parse error: unexpected symbol ´int' " in the "public int y;" line ? 2 Answers
flickering light 1 Answer
What is wrong with the script 1 Answer
Unexpected symbol 'Flip' and 'else' 1 Answer