Results 1 to 5 of 5

Thread: Xml serialization

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Xml serialization

    Hi,

    I have a little problem.
    I have made a 'game editor' in wich i can make maps for my 'game'. I can save the maps in my 'game editor' so I can load them in my 'game' (other project file).

    My Classes look like this:

    Code:
    Imports System.IO
    Imports System.Xml.Serialization
    
    Public Class MapSaver
    
        Public Shared Sub SaveMap(ByVal Map As Map, ByVal fileName As String)
    
            Dim ser As New XmlSerializer(GetType(Map))
            Dim fs As New FileStream(fileName, FileMode.Create)
    
            ser.Serialize(fs, Map)
    
            fs.Close()
            fs.Dispose()
    
        End Sub
    
    End Class
    
    Public Class Map
    
        Public Tile(MAX_X * MAX_Y) As TileRec
    
        Public MAX_X As Integer
        Public MAX_Y As Integer
    
        Public Npc(50) As MapNpcRec
        Public Item(50) As MapItemRec
    
        Public Name As String
        Public Moral As Integer
        Public SwitchOver(3) As Integer
    
        Public Structure MapItemRec
    
            Public X As Integer
            Public Y As Integer
            Public ItemID As Integer
            Public ItemAmmount As Integer
    
        End Structure
    
        Public Structure MapNpcRec
    
            Public SpawnX As Integer
            Public SpawnY As Integer
            Public X As Integer
            Public Y As Integer
            Public NpcID As Integer
            Public ItemAmmount As Integer
    
        End Structure
    
        Public Structure LayerRec
    
            Public Ground As TileDataRec
            Public Mask As TileDataRec
            Public Mask2 As TileDataRec
            Public Fringe As TileDataRec
            Public Fringe2 As TileDataRec
    
        End Structure
    
        Public Structure TileRec
    
            Public Layer As LayerRec
            Public Attribute As AttributeRec
    
        End Structure
    
        Public Structure TileDataRec
    
            Public imgX As Integer
            Public imgY As Integer
            Public Tileset As Integer
            Public Draw As Boolean
    
        End Structure
    
        Public Structure AttributeRec
    
            Public Attribute As Integer
            Public Value As Integer
            Public Value2 As Integer
    
        End Structure
    
    End Class
    
    Public Class MapLoader
    
        Public Shared Function LoadMap(ByVal fileName As String) As Map
    
            Dim ser As New XmlSerializer(GetType(Map))
            Dim fs As New FileStream(fileName, FileMode.Open)
            Dim ret As Map
    
            ret = DirectCast(ser.Deserialize(fs), Map)
    
            fs.Close()
            fs.Dispose()
    
            Return ret
    
        End Function
    
    End Class
    Now the problem is, that my 'game' will not read the maps from the 'game editor'. but the 'game editor' can load saved maps what I made earlier with it.

    This means its possible to Save & Load maps in my 'game editor', but i can't load the maps in my 'game'. Can someone help me so I can use my maps that I make in my''game editor' are also useable in my 'game'?

    thanks

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Xml serialization

    Have you included all the classes in both projects? The most likely explanations would be that the game does not have the same definition of 'map' or cannot deserialize one properly.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Re: Xml serialization

    Quote Originally Posted by dunfiddlin View Post
    Have you included all the classes in both projects? The most likely explanations would be that the game does not have the same definition of 'map' or cannot deserialize one properly.
    Yes they both have the same classes and i do not have any errors. If I ask for the 'map name' it will just say there's no map name

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Xml serialization

    Where are the files saved? If you're not using absolute paths are you sure that both projects are looking in the same place?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2011
    Posts
    118

    Re: Xml serialization

    Quote Originally Posted by dunfiddlin View Post
    Where are the files saved? If you're not using absolute paths are you sure that both projects are looking in the same place?
    I guess i found the problem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width