Mirage Source
acheiving urber speed question. - 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: acheiving urber speed question. (/showthread.php?tid=756)



acheiving urber speed question. - genusis - 17-02-2007

Well I was doing the tutorial called Achieving urber speed, and I got to the point where i have to change the Load Classes sub.

Code:
Sub Load Classes()
Dim FileName As String
Dim i As Long
Dim nFileNum As Integer

nFileNum = FreeFile
    Open FileName For Binary As #nFileNum
    Call CheckClasses
    
    FileName = App.Path & "\data\classes.bin"
    
    Max_Classes = Val(GetVar(FileName, "INIT", "MaxClasses"))
    
    ReDim Class(0 To Max_Classes) As ClassRec
    
    Call ClearClasses
    
    For i = 0 To Max_Classes
        Class(i).Name = GetVar(FileName, "CLASS" & i, "Name")
        Class(i).Sprite = GetVar(FileName, "CLASS" & i, "Sprite")
        Class(i).STR = Val(GetVar(FileName, "CLASS" & i, "STR"))
        Class(i).DEF = Val(GetVar(FileName, "CLASS" & i, "DEF"))
        Class(i).SPEED = Val(GetVar(FileName, "CLASS" & i, "SPEED"))
        Class(i).MAGI = Val(GetVar(FileName, "CLASS" & i, "MAGI"))
        
        DoEvents
    Next i
End Sub

in the tutorial It says
Code:
Then instead of GetVar, replace it with the Get statement, Get #nFileNum, ,Max_Classes

Replace all the other GetVar stuff with the Get stuff.

Close the file at the end, Close #nFileNum


The problem here is that The tutorial does not explain how to change the getvar stuff. It just says to change them with the Get #nFileNum, ,Max_Classes, which always throws an error.

I did mine like this
Code:
Class(i).Name = [color=red]Get[/color] #nFileNum, ,Max_Classes
how would you do this?


- William - 17-02-2007

Should probably be:
Code:
Get #nFileNum, , Class(i).Name

or

Code:
Get #nFileNum, , Class(i)



- genusis - 17-02-2007

OK I think I got everything there ,but
Code:
Max_Classes = Val(GetVar(FileName, "INIT", "MaxClasses"))


so far it looks like this for me.

Code:
Sub LoadClasses()
Dim FileName As String
Dim i As Long
Dim nFileNum As Integer

nFileNum = FreeFile
    Open FileName For Binary As #nFileNum
    Call CheckClasses
    
    FileName = App.Path & "\data\classes.bin"
    
    Max_Classes = Val(GetVar(FileName, "INIT", "MaxClasses"))
    
    ReDim Class(0 To Max_Classes) As ClassRec
    
    Call ClearClasses
    
    For i = 0 To Max_Classes
    Get #nFileNum, , Class(i).Name
    Get #nFileNum, , Class(i).Sprite
    Get #nFileNum, , Class(i).STR
    Get #nFileNum, , Class(i).DEF
    Get #nFileNum, , Class(i).SPEED
    Get #nFileNum, , Class(i).MAGI
        'Class(i).Name = GetVar(FileName, "CLASS" & i, "Name")
        'Class(i).Sprite = GetVar(FileName, "CLASS" & i, "Sprite")
        'Class(i).STR = Val(GetVar(FileName, "CLASS" & i, "STR"))
        'Class(i).DEF = Val(GetVar(FileName, "CLASS" & i, "DEF"))
        'Class(i).SPEED = Val(GetVar(FileName, "CLASS" & i, "SPEED"))
        'Class(i).MAGI = Val(GetVar(FileName, "CLASS" & i, "MAGI"))
        
        DoEvents
    Next i
End Sub

So how would I change
Code:
Max_Classes = Val(GetVar(FileName, "INIT", "MaxClasses"))



- William - 17-02-2007

Code:
Get #nFileNum, , Max_Classes



- genusis - 17-02-2007

so like this

Code:
Max_Classes = Get #nFileNum, , Max_Classes

or just

Code:
Get #nFileNum, , Max_Classes



- William - 17-02-2007

Just
Code:
Get #nFileNum, , Max_Classes



- Robin - 17-02-2007

Instead of getting and putting all that data, you could just do the type array in one go.


- William - 17-02-2007

Yeah, like this:
Code:
Get #nFileNum, , Class(i)



- genusis - 17-02-2007

OK got that part well now I'm working on trying to convert my items to binary to. The only problem is

Code:
Sub SaveItem(ByVal ItemNum As Long)
Dim FileName As String

    FileName = App.Path & "\data\items.bin"
    
    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
    Call PutVar(FileName, "ITEM" & ItemNum, "Name", Trim(Item(ItemNum).Name))
    Call PutVar(FileName, "ITEM" & ItemNum, "Pic", Trim(Item(ItemNum).Pic))
    Call PutVar(FileName, "ITEM" & ItemNum, "Type", Trim(Item(ItemNum).Type))
    Call PutVar(FileName, "ITEM" & ItemNum, "Data1", Trim(Item(ItemNum).Data1))
    Call PutVar(FileName, "ITEM" & ItemNum, "Data2", Trim(Item(ItemNum).Data2))
    Call PutVar(FileName, "ITEM" & ItemNum, "Data3", Trim(Item(ItemNum).Data3))
End Sub
And
Code:
Sub LoadItems()
Dim FileName As String
Dim i As Long

    Call CheckItems
    
    FileName = App.Path & "\data\items.bin"
    
    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
        'Item(i).Name = GetVar(FileName, "ITEM" & i, "Name")
        'Item(i).Pic = Val(GetVar(FileName, "ITEM" & i, "Pic"))
        'Item(i).Type = Val(GetVar(FileName, "ITEM" & i, "Type"))
        'Item(i).Data1 = Val(GetVar(FileName, "ITEM" & i, "Data1"))
        'Item(i).Data2 = Val(GetVar(FileName, "ITEM" & i, "Data2"))
        'Item(i).Data3 = Val(GetVar(FileName, "ITEM" & i, "Data3"))
        
        DoEvents
    Next i
End Sub

use a different method. one uses
Code:
'Item(i).
And the other uses
Code:
"ITEM" & ItemNum
how would i do this just give me an example for the
Code:
"ITEM" & ItemNum



- funkynut - 17-02-2007

Reason their different is because ones loading and ones to save.

You should be using Put instead of Get, and use ItemNum instead of i
Code:
put #nFileNum, , Item(itemnum).Pic

And in both the example you've shown, you have forgotten to open the file

Code:
Open FileName For Binary As #nFileNum

Oh, and you've forgotten to close it afterwards in every peice you've shown
Code:
Close #nFileNum

And even if you got it to save load, I got a feeling it wont run right, in my mind when I run that, it loads everything fine, but when you save, you'll only save the last item[/code]


- Obsidian - 17-02-2007

The tutorial i recently posted in the 'Optimized Tutorials' Section, called Simple Binary (Single File) Saving... is the same tutorial you were looking at, but much more simplified and easy to use (and it gives you the same speed as the tutorial you're currently struggling with).


- genusis - 18-02-2007

thank you guys for your help. Oh and Open FileName For Binary As #nFileNum, and Close #nFileNum where not added becuase I didnt add them yet, but I didnt forget about them lol. Thank you.