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 LeWyRaWr · Feb 21, 2012 at 08:45 AM · javascriptloadingxmlsavingclasses

Saving data to xml file (I have the loading down)

Hey guys, I've been working on a 'create a class' system similar to Call of Duty. I've managed to make an XML script that will load the classes data from an XML file. This is how the xml is set out:

     <mpdata>
        <class1 name="Assault">
          <data>0</data>
          <data>1</data>
          <data>2</data>
          <data>3</data>
          <data>4</data>
          <data>5</data>
          <data>6</data>
          <data>7</data>
          <data>8</data>
          <data>9</data>
        </class1>
     </mpdata>

Each class is seperated by the 'class1','class2' etc. I wrote this script for loading them on a test basis:

 import System.Xml;
 
 var showData : int;
 
 var class1name : String;
 var class1 : String[];
 
 function Start()
 {
 DataRead();
 }
 
 function DataRead()
 {
     showData = 0;
     class1name = "NULL";
     class1 = null;
 
     var reader:XmlReader = XmlReader.Create("mpdata.xml");
    
       while(reader.Read())
       {
         // CLASS 1
          if(reader.IsStartElement("class1"))
          {
             class1name=reader.GetAttribute("name");
             class1 = new String[10];
 
             for(showData = 0;showData<10;showData++)
             {
                 reader.Read();
                 if(reader.IsStartElement("data"))
                 {
                     class1[showData] = reader.ReadString();
                 }
             }
             showData=0;
          }
          
       }
 }

 function OnGUI()
 {
         GUI.Label(Rect(0,0,200,20), class1name);
         GUI.Label(Rect(0,20,200,100), "Primary Weapon: "+class1[0]);
         GUI.Label(Rect(0,40,200,100), "Primary Sight: "+class1[1]);
         GUI.Label(Rect(0,60,200,100), "Primary Attachment: "+class1[2]);
         GUI.Label(Rect(0,80,200,100), "Secondary Weapon: "+class1[3]);
         GUI.Label(Rect(0,100,200,100), "Secondary Sight: "+class1[4]);
         GUI.Label(Rect(0,120,200,100), "Secondary Attachment: "+class1[5]);
         GUI.Label(Rect(0,140,200,100), "Equipment: "+class1[6]);
         GUI.Label(Rect(0,160,200,100), "Grenade Type: "+class1[7]);
         GUI.Label(Rect(0,180,200,100), "Alpha Ability: "+class1[8]);
         GUI.Label(Rect(0,200,200,100), "Bravo Ability: "+class1[9]);
 }

The information is picked up from another script which loads it into it's own variables, like 'C1PrimaryWeapon' etc, so then I can edit those variables from within the classes menu. My question is how am I able to write to the XML file with the information after it's been changed with the new variables?

Comment
Add comment · Show 2
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 flamy · Feb 21, 2012 at 09:45 AM 0
Share

http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx

avatar image LeWyRaWr · Feb 21, 2012 at 11:08 AM 0
Share

I don't really dabble in C#, is there any example coding there in Javascript?

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

C# Save/Load - Save entire class contents? 1 Answer

Retrieving basic Strings and Ints from XML Files (JS) 0 Answers

What Method To Use When Saving? 1 Answer

Saving Game Confussion 1 Answer

Saving frequently throughout game lifecycle (Android) 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