Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • 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.

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

Visual Studio UnResponsive!!!! 0 Answers

Unity3d - Attach to Unity not working 3 Answers

How to execute Unitys Build on an Android Emulator with Win 7 64 bit, without Hyper-V, without VT-x or NX or SVM 0 Answers

Error building for Microsoft Store using visual studio 2017 0 Answers

How to change C# version in Visual Studio with Unity Project 0 Answers


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