jsorr2 Posted November 17, 2012 Author Share Posted November 17, 2012 Trying to call Monster's name from file. Come's up with a blank. What am I doing wrong?```Sub SaveMonsters() Dim i As Long For i = 1 To MAX_MONSTERS Call SaveMonster(i) NextEnd SubSub SaveMonster(ByVal MonstersNum As Long) Dim filename As String Dim F As Long filename = App.path & "\data\Monsters\Monsters" & MonstersNum & ".dat" F = FreeFile Open filename For Binary As #F Put #F, , Monsters(MonstersNum) Close #FEnd SubSub LoadMonsters() Dim filename As String Dim i As Long Dim F As Long Call CheckMonsters For i = 1 To MAX_MONSTERS filename = App.path & "\data\BaseMonster" & ".txt" F = FreeFile Open filename For Binary As #F Get #F, , Monsters(i) Close #F NextEnd SubSub CheckMonsters() Dim i As Long For i = 1 To MAX_MONSTERS If Not FileExist("\Data\Monsters\Monsters" & i & ".dat") Then Call SaveMonsters(i) End If NextEnd SubSub ClearMonster(ByVal index As Long) Call ZeroMemory(ByVal VarPtr(Monsters(index)), LenB(Monsters(index))) Monsters(index).MonstersName = vbNullStringEnd SubSub ClearMonsters() Dim i As Long For i = 1 To MAX_MONSTERS Call ClearMonster(i) Next End Sub``````Public Function GetFileName(ID As Long) As String GetFileName = App.path & "\data\Monsters\Monsters" & ID & ".dat"End FunctionPublic Function GetMonstersName(ID As Long) As StringDim filename As StringIf ID > 0 And ID <= 50 Then filename = GetFileName(ID) GetMonstersName = GetVar(filename, CStr(ID), "Name")Else GetMonstersName = OutBoundsEnd IfEnd Function``` Link to comment Share on other sites More sharing options...
Matt Posted November 17, 2012 Share Posted November 17, 2012 You could alternatively do something along the lines of```npc(index).name```It would be much easier than getting the name from the file itself. Link to comment Share on other sites More sharing options...
abhi2011 Posted November 17, 2012 Share Posted November 17, 2012 Why would u use a getvar when it is a .dat file? Link to comment Share on other sites More sharing options...
Guest Posted November 17, 2012 Share Posted November 17, 2012 You're doing a GetVar from a .txt file whilst your monsters are saved in a binary .dat. All it should be is GetMonsterName = Monster(ID).Name. Link to comment Share on other sites More sharing options...
Guest Posted November 17, 2012 Share Posted November 17, 2012 Woops, delete this post. Link to comment Share on other sites More sharing options...
tslusny Posted November 17, 2012 Share Posted November 17, 2012 You are saving monsters to .dat file, but you are reading them from .txt file ![:D](http://www.touchofdeathforums.com/community/public/style_emoticons/<#EMO_DIR#>/biggrin.png) Link to comment Share on other sites More sharing options...
abhi2011 Posted November 18, 2012 Share Posted November 18, 2012 Use```open filename for binary as #Finput,,monster(index)close #f```i wrote it out of memory so the input statement might be wrong.For the name, after loading all you monster use```GetMonsterName = Monster(index).Name```Or something. Again you will have to edit it to work properly. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now