Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pixatlazaki · Dec 30, 2014 at 05:59 AM · unexpected-symbolrefactor

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.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image sysameca · Dec 30, 2014 at 07:43 AM 0
Share

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.

avatar image NoseKills · Dec 30, 2014 at 08:17 AM 1
Share

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.

avatar image pixatlazaki · Dec 30, 2014 at 10:16 AM 0
Share

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.

avatar image sysameca · Dec 30, 2014 at 03:06 PM 0
Share

great to know you found out the solution :)

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer Wiki

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Dec 30, 2014 at 08:28 PM 1
Share

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.

avatar image pixatlazaki · Dec 31, 2014 at 12:37 AM 0
Share

I think that's probably what happened.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges