x


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?

more ▼

asked Feb 21 '12 at 08:45 AM

LeWyRaWr gravatar image

LeWyRaWr
1 2 2 3

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

Feb 21 '12 at 11:08 AM LeWyRaWr
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x297
x289
x256
x133
x124

asked: Feb 21 '12 at 08:45 AM

Seen: 672 times

Last Updated: Feb 21 '12 at 12:07 PM