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?
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Should probably be:
Code: Get #nFileNum, , Class(i).Name
or
Code: Get #nFileNum, , Class(i)
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"))
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Code: Get #nFileNum, , Max_Classes
so like this
Code: Max_Classes = Get #nFileNum, , Max_Classes
or just
Code: Get #nFileNum, , Max_Classes
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Just Code: Get #nFileNum, , Max_Classes
Posts: 2,742
Threads: 115
Joined: Jun 2006
Reputation:
0
Instead of getting and putting all that data, you could just do the type array in one go.
Quote:Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?
Posts: 2,605
Threads: 412
Joined: Nov 2021
Reputation:
0
Yeah, like this:
Code: Get #nFileNum, , Class(i)
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 And the other uses how would i do this just give me an example for the
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
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]
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).
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.
|