• 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 /
  • Help Room /
avatar image
0
Question by Dragonlord3989 · Dec 29, 2015 at 08:07 AM · unity 5visual studio

Noob problem with C# in unity

So this is my first time using c# and I am watching a youtube video which is where I got the code from but I typed it word for word any time I try and run it I get these errors I am brand new to unity and c# so any help would be great

alt text

 using UnityEngine;
 using System.Collections;
 using UnityEditor;
 using System.Text;
 using System.IO;
 using System.Text.RegularExpressions;
 using System.Collections.Generic;
 
 public class DialougeParse : MonoBehaviour {
 
     List<DialougeLine> lines;
 
     struct DialougeLine {
         string name;
         string content;
         int pose;
 
         public DialougeLine(string n, string c, int p)
         {
             name = n;
             content = c;
             pose = p;
         }
     }
     // Use this for initialization
     void Start () {
         string file = "Dialouge";
         string sceneNum = EditorApplication.currentScene;
         sceneNum = Regex.Replace(sceneNum, "[^0-9]", "");
         file += sceneNum;
         file += ".txt";
 
         LoadDialouge(file);    
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void LoadDialouge(string filename)
     {
         string file = "Assets/Resources/" + filename;
         string line;
         StreamReader r = new StreamReader(file);
 
         using(r)
         {
             do
             {
                 line = r.ReadLine();
                 if(line !=null)
                 {
                     string[] line_vaulues = line.Split(",);
                     DialougeLine line_entry = new DialougeLine(line_values[0], line_values[1], int.Parse (line_values[2]));
                     lines.Add(line_entry);
                 }
             }
 
             while (line != null);
             r.Close
             }
     }
 }
 


ss2015-12-29at060356.png (68.9 kB)
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by unity-huunity · Dec 29, 2015 at 08:12 AM

line 54 you forgot " symbol

string[] line_vaulues = line.Split(","); // - change to this

Comment
Add comment · 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
0

Answer by Dragonlord3989 · Dec 29, 2015 at 08:21 AM

Thanks for that but now I am getting a error at line 61,20: error cs8025: Parasing error

  using UnityEngine;
  using System.Collections;
  using UnityEditor;
  using System.Text;
  using System.IO;
  using System.Text.RegularExpressions;
  using System.Collections.Generic;
  
  public class DialougeParse : MonoBehaviour {
  
      List<DialougeLine> lines;
  
      struct DialougeLine {
          string name;
          string content;
          int pose;
  
          public DialougeLine(string n, string c, int p)
          {
              name = n;
              content = c;
              pose = p;
          }
      }
      // Use this for initialization
      void Start () {
          string file = "Dialouge";
          string sceneNum = EditorApplication.currentScene;
          sceneNum = Regex.Replace(sceneNum, "[^0-9]", "");
          file += sceneNum;
          file += ".txt";
  
          LoadDialouge(file);    
      }
      
      // Update is called once per frame
      void Update () {
      
      }
  
      void LoadDialouge(string filename)
      {
          string file = "Assets/Resources/" + filename;
          string line;
          StreamReader r = new StreamReader(file);
  
          using(r)
          {
              do
              {
                  line = r.ReadLine();
                  if(line !=null)
                  {
                      string[] line_vaulues = line.Split(",");
                      DialougeLine line_entry = new DialougeLine(line_values[0], line_values[1], int.Parse (line_values[2]));
                      lines.Add(line_entry);
                  }
              }
  
              while (line != null);
              r.Close();
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 unity-huunity · Dec 29, 2015 at 08:46 AM 0
Share

try to put } } } after last line

avatar image Dragonlord3989 unity-huunity · Dec 29, 2015 at 09:33 AM 0
Share

Ok so this is what I changed it to but it caused more errors while (line != null); r.Close(); } } }

avatar image
0

Answer by A_Li_N · Dec 30, 2015 at 05:29 AM

Either you didn't copy your entire class into that code snippet or you are missing quite a bit of code in your class :)

C# is done in blocks of code surrounded with { and }. So you have:

     void LoadDialouge(string filename)
       {
           string file = "Assets/Resources/" + filename;
           string line;
           StreamReader r = new StreamReader(file);
   
           using(r)
           {
               do
               {
                   line = r.ReadLine();
                   if(line !=null)
                   {
                       string[] line_vaulues = line.Split(",");
                       DialougeLine line_entry = new DialougeLine(line_values[0], line_values[1], int.Parse (line_values[2]));
                       lines.Add(line_entry);
                   }
               }
   
               while (line != null);
               r.Close();

You see that LoadDialog opens with a {, then 'using' opens with a {, then 'do' opens with a {. You close the 'do' on line 58 but do not close the 'using', LoadDialog or the class itself. That is where the suggestion of adding }}} comes in. Adding those close the 'using', LoadDialog and class blocks of code.

Regarding further errors, it's best to post them so we know what you are experiencing. My quick review shows your line 54 has 'line_vaulues' (extra 'u') where line 55 is looking for 'line_values'.

Also, line 54: line.Split(",")... Split requires a character, not a string. Try changing those double quotes to single quotes: line.Split(',');

Comment
Add comment · 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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

43 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 5+ compatibility with VS2012 - ? 0 Answers

visual studio tools for unity problem 1 Answer

VS Code or visual studio? 1 Answer

Building a new PC and wondering what my options are for backing up all my Unity / Visual Studio settings / preferences etc 2 Answers

Visual Studio 2015 keeps crashing... 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges