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 Snivy · Mar 07, 2013 at 12:32 AM · savexml

Assets/Save Game Script.cs(87,45): error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `='

OH NO! It's me again! As the title said, Unity keeps giving me the error, but I can't seem to spot it. Feel free to help.

 using UnityEngine;
 using System.Collections;
 using System.Xml;
 using System.Xml.Serialization;
 using System.IO;
 using System.Text;
 
 //The tutorial referenced this site:
 //http://www.eggheadcafe.com/articles/system.xml.xmlserialization.asp
 
 public class _GameSaveLoad : MonoBehaviour {
     
     //These are the local private members.
     Rect _Save, _Load, _SaveMSG, _LoadMSG;
     bool _ShouldSave, ShouldLoad, _SwitchSave, _SwitchLoad;
     string _FileLocation, _FileName;
     public GameObject _Player;
     UserData myData;
     string _PlayerName;
     string _data;
     
     Vector3 VPosition;
     
     //Set up new rectangles for the loacl members.
     void Start () 
     {
         //New rectangles are set.
         _Save=new Rect(10,80,100,20);
         _Load=new Rect(10,100,100,20);
         _SaveMSG=new Rect(10,120,400,40);
         _LoadMSG=new Rect(10,140,400,40);
         
         //Where we are loading/saving from.
         _FileLocation=Application.dataPath;
         _FileName="SaveData.xml";
         
         //Set the name to Joe Schmoe.
         _PlayerName = "Joe Schmoe";
         
         //Make something to store the info to.
         myData=new UserData();
     }
     
     // Update is called once per frame
     void Update () {}
     
     void OnGUI()
     {
         //*****************************************************************************************
         //Load the player...
         //*****************************************************************************************
         if(GUI.Button(_GameSaveLoad, "Load"))
         {
             GUI.Label(_LoadMSG, "Loading from: " +_FileLocation);
             //Load it into the myData
             LoadXML();
             if(_data.ToString() != "")
             {
                 //myData has to reference a real thing (UserData)
                 //or else it won't load correctly.
                 myData = (UserData)DeserializeObject(_data);
                     //Set the player's position based on load
                 VPosition=new Vector3(myData._iUser.x,myData._iUser.y,myData._iUser.z);
                 _Player.transform.position=VPosition;
                 //Now we show that we loaded it correctly.
                 Debug.Log(myData._iUser.name);
             }
         }
         
         //*****************************************************************************************
         //Saving the player...
         //*****************************************************************************************
         if(GUI.Button(_GameSaveLoad, "Save"))
         {
             GUI.Label(_SaveMSG, "Saving to: "+_FileLocation);
             myData._iUser.x=_Player.transform.position.x;
             myData._iUser.y=_Player.transform.position.y;
             myData._iUser.z=_Player.transform.position.z;
             myData._iUser.name=_PlayerName;
             
             //Create the XML.
             CreateXML();
             Debug.Log(_data);
         }
         
         /* These came from the tut (http://wiki.unity3d.com/index.php?title=Save_and_Load_from_XML).*/
         string UTF8ByteArrayToString(byte[] characters)
         {
             UTF8Encoding encoding = new UTF8Encoding(); 
           string constructedString = encoding.GetString(characters); 
           return (constructedString);
         }
         
         byte[] StringToUTF8ByteArray(string pXmlString)
         {
             UTF8Encoding encoding = new UTF8Encoding();
             byte[] byteArray = encoding.GetBytes(pXmlString);
             return byteArray;
         }
         
         //Now we serialize the data objects
         string SerializeObject(object pObject)
         {
             string XmlizedString = null;
             MemoryStream memoryStream = new MemoryStream();
             XmlSerializer xs = new XmlSerializer(typeof(UserData));
             XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
             xs.Serialize(XmlTextWriter, pObject);
             memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
             XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
             return XmlizedString;
         }
         
         //Here we put it back to it's normal state.
         object DeserializeObject(string pXmlizedString)
         {
             XmlSerializer xs = new XmlSerializer(typeof(UserData));
             MemoryStream memoryStream = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
             XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
             return xs.Deserialize(memoryStream);
         }
         
         //Now the save and load methods.
         void CreateXML()
         {
             StreamWriter writer;
             FileInfo t =new FileInfo(_FileLocation+"\\"+ _FileName);
             if(!t.Exists)
             {
                 XmlWriter = t.CreateText();
             }
             else
             {
                 t.Delete();
                 writer = t.CreateText();
             }
             writer.Write(_data);
             writer.Close();
             Debug.Log("File written safely.");
         }
         
         void LoadXML()
         {
             StreamReader r = File.OpenText(_FileLocation+"\\"+ _FileName);
             string _info = r.ReadToEnd();
             r.Close();
             _data=_info;
             Debug.Log("Loaded file!");
         }
     }
     
     //UserData is the custom class that holds the info and data about the objects remember?
     public class UserData
     {
         //We have to define the defaults first.
         public DemoData _iUser;
         //Defualt doesn't quite do much right now...
         public UserData() {}
         
         //Anything we want to store in the file is defined here.
         public struct DemoData
         {
             public float x;
             public float y;
             public float z;
             public string name;
         }
     }
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by robertbu · Mar 07, 2013 at 12:38 AM

You are trying to declare a number of methods inside of OnGUI(). I think if you put a '}' on line 85 to close OnGUI(), it will address this specific problem. You will want to redo your indenting to place all these new methods at the same level as OnGUI().

Comment
Add comment · Show 1 · 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 Snivy · Mar 07, 2013 at 12:40 AM 0
Share

Thank you so much. It's stuff like that gets me every time.

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

10 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

Related Questions

Write to XML-file within Assets\Resources 1 Answer

Xml Saving and Loading Problems 1 Answer

SaveLoad Profile c# to xml 4 Answers

How to create an XML file in Unity 1 Answer

Save and Load from XML help 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