Jump to content

Converting to XML


Recommended Posts

This is the way an items stats are currently saved:

For i = 0 To Stats.StatCount - 1
    FilePutObject(F, Item(itemNum).AddStat(i))

I am trying set this up to to convert to xml:

For i = 0 To Stats.StatCount - 1
    itemData.AddStat(i) = Item(itemNum).AddStat(i)

This is throwing a null exception and I'm not sure how to set this to work.  I already have my serializer/deserializer set to handle the stuff that needs to be saved.

Link to comment
Share on other sites

Okay, here is everything for the SaveItem sub.  First is how it is currently done in the engine:

Dim filename As String
        Dim F As Long
        filename = Application.StartupPath & "\DataFiles\items\item" & itemNum & ".dat"
        F = FreeFile()
        FileOpen(F, filename, OpenMode.Binary, OpenAccess.Write, OpenShare.Default)
        FilePutObject(F, Item(itemNum).Name)
        FilePutObject(F, Item(itemNum).Pic)
        FilePutObject(F, Item(itemNum).Type)
        FilePutObject(F, Item(itemNum).Data1)
        FilePutObject(F, Item(itemNum).Data2)
        FilePutObject(F, Item(itemNum).Data3)
        FilePutObject(F, Item(itemNum).ClassReq)
        FilePutObject(F, Item(itemNum).AccessReq)
        FilePutObject(F, Item(itemNum).LevelReq)
        FilePutObject(F, Item(itemNum).Mastery)
        FilePutObject(F, Item(itemNum).Price)
        For i = 0 To Stats.StatCount - 1
            FilePutObject(F, Item(itemNum).AddStat(i))
        FilePutObject(F, Item(itemNum).Rarity)
        FilePutObject(F, Item(itemNum).Speed)
        FilePutObject(F, Item(itemNum).Handed)
        FilePutObject(F, Item(itemNum).BindType)
        For i = 0 To Stats.StatCount - 1
            FilePutObject(F, Item(itemNum).StatReq(i))
        FilePutObject(F, Item(itemNum).Animation)
        FilePutObject(F, Item(itemNum).Paperdoll)
        FilePutObject(F, Item(itemNum).Stackable)

Now, I am wanting to change that section to use my serializer:

Dim itemData As Types.ItemRec = New Types.ItemRec
        itemData.Name = Item(itemNum).Name
        itemData.Pic = Item(itemNum).Pic
        itemData.Type = Item(itemNum).Type
        itemData.Data1 = Item(itemNum).Data1
        itemData.Data2 = Item(itemNum).Data2
        itemData.Data3 = Item(itemNum).Data3
        itemData.ClassReq = Item(itemNum).ClassReq
        itemData.AccessReq = Item(itemNum).AccessReq
        itemData.LevelReq = Item(itemNum).LevelReq
        itemData.Mastery = Item(itemNum).Mastery
        itemData.Price = Item(itemNum).Price
        For i = 0 To Stats.StatCount - 1
            itemData.AddStat(i) = Item(itemNum).AddStat(i)
        itemData.Rarity = Item(itemNum).Rarity
        itemData.Speed = Item(itemNum).Speed
        itemData.Handed = Item(itemNum).Handed
        itemData.BindType = Item(itemNum).BindType
        For i = 0 To Stats.StatCount - 1
            itemData.StatReq(i) = Item(itemNum).StatReq(i)
        itemData.Animation = Item(itemNum).Animation
        itemData.Paperdoll = Item(itemNum).Paperdoll
        itemData.Stackable = Item(itemNum).Stackable
        Dim filePath As String = Application.StartupPath & "\DataFiles\items\item" & itemNum & ".ori"
        ModObjectSerializer.SerializeObject(filePath, itemData)

When it hits the first For loop it comes up with the error.  Until it hits that everything else is going fine from what I can tell.  Since I deleted all of my items there is nothing in the folder.  I'm also changing the extension from .dat to .ori so that eventually I can assign these to open in an external editor.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...