Mirage Source
Saving Items problem - Printable Version

+- Mirage Source (https://mirage-engine.uk/forums)
+-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61)
+--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18)
+---- Forum: General (https://mirage-engine.uk/forums/forumdisplay.php?fid=17)
+---- Thread: Saving Items problem (/showthread.php?tid=481)



Saving Items problem - Tony - 16-12-2006

Well this is the problem, If I edit an item and add items it and then press ok. I go to Edit Item Index and it has all the items I edited/added. But once I restart the server It only saves the last item I added or in the list(index). Im using binary files btw.

Subs relating to items..

Code:
Sub SaveItems()
Dim i As Long
    
    For i = 1 To MAX_ITEMS
        Call SaveItem(i)
    Next i
End Sub

Sub SaveItem(ByVal ItemNum As Long)
Dim FileName As String
Dim nFileNum As Integer

    FileName = App.Path & "\data\items.dat"
    
    nFileNum = FreeFile
    Open FileName For Binary As #nFileNum

    Put #nFileNum, , Item(ItemNum).Name
    Put #nFileNum, , Item(ItemNum).Pic
    Put #nFileNum, , Item(ItemNum).Type
    Put #nFileNum, , Item(ItemNum).Data1
    Put #nFileNum, , Item(ItemNum).Data2
    Put #nFileNum, , Item(ItemNum).Data3
    
    Close #nFileNum

End Sub

Sub LoadItems()
Dim FileName As String
Dim i As Long
Dim nFileNum As Integer

    Call CheckItems
    
    FileName = App.Path & "\data\items.dat"
    nFileNum = FreeFile
    Open FileName For Binary As #nFileNum
    
    For i = 1 To MAX_ITEMS
        Get #nFileNum, , Item(i).Name
        Get #nFileNum, , Item(i).Pic
        Get #nFileNum, , Item(i).Type
        Get #nFileNum, , Item(i).Data1
        Get #nFileNum, , Item(i).Data2
        Get #nFileNum, , Item(i).Data3
        DoEvents
    Next i
    
    Close #nFileNum
End Sub

Sub CheckItems()
    If Not FileExist("data\items.dat") Then
        Call SaveItems
    End If
End Sub

:: Pando


- Matt - 16-12-2006

This is the system I use, that works just as good, saving each item in it's own file, like the maps do.

Code:
Sub SaveItems()
Dim i As Integer

For i = 1 To MAX_ITEMS
    If Not FileExist("data\items\item" & i & ".doi", True) Then
        Call SetStatus("Saving items... " & i & "/" & MAX_ITEMS)
        DoEvents
        Call SaveItem(i)
    End If
Next i

End Sub


Sub SaveItem(ByVal ItemNum As Integer)
Dim FileName As String
Dim f As Long
FileName = App.Path & "\data\Items\Item" & ItemNum & ".doi"

f = FreeFile
Open FileName For Binary As #f
Put #f, , Item(ItemNum)
Close #f
End Sub

Sub LoadItems()
Dim FileName As String
Dim i As Long, f As Long

    Call CheckItems

For i = 1 To MAX_ITEMS
    Call SetStatus("Loading items... " & i & "/" & MAX_ITEMS)
    FileName = App.Path & "\data\items\item" & i & ".doi"
    f = FreeFile
    Open FileName For Binary As #f
    Get #f, , Item(i)
Close #f

DoEvents
Next i

End Sub

Sub CheckItems()
    Call SaveItems
End Sub



- Tony - 16-12-2006

Hmm can you tell me whats my problem first?

:: Pando


- Matt - 16-12-2006

I didn't use the system you have, I don't like it. So I don't know what your issue is. Maybe something with the clearitems, I'm not sure.


- Tony - 16-12-2006

What about the loading then?
(it doesn't work)


:: Pando