-
text file searchout???
:confused:
The game that I've been working on for several weeks now, called Crusader: Battle for the Throne, seems to have run into an impass... :eek:
I kept trying to create every value in the form itself, but since it was a split string and I had nearly 60 different pieces of armour alone, it got a little too hairy and I gave up on that plan. Now, I'm trying to read all the data in from a text file.
Fairly simple question:
How can I have VB look through the file for [Armour], from there have it look for the first tag titled [Bronze], and from there have it look for [Plate Mail]?
It needs to read to the first tag alone because I will have 8 different references to [Plate Mail] for the different materials used.
Any help would be greatly appreciated!
-
I would build it like an Ini file instead..
[Armour]
Bronze1=Platemail
Bronze2=Chainmail
etc..
-
It's like that, but I don't want to load 500 variables into location "x" and have to worry about them later. I'd much rather just search for them when I need them. Even if the text file was changed, all of the values would be changed just like an ini file.
I know how to read ini files from one of my favorite games, Yuri's Revenge. I'm a mod maker with that game, and I love their ini file. But that is also an RTS game. Crusader is text-based.
-
You could list all of your combinations in the text file line by line then use split to look thru them...
Sample text file
Armour,Chest,Silver,PlateMail
Armour,Chest,Copper,PlateMail
Armour,Chest,Bronze,PlateMail
Armour,Chest,Steel,PlateMail
TheItem()=Split(TheString,",")
If TheItem(0) = "Armour" & TheItem(1) = "Chest" & TheItem(2) = "Bronze" & TheItem(3) = "Platemail" then msgbox "Found it"
Of course that would go into a loop that is looping thru each line in the text file
-
All I'm worried about at this juncture is searching through a text file. Once I get that, I'll have all of my problems solved.
-
Well, this is what you are trying to do:
Fairly simple question:
How can I have VB look through the file for [Armour], from there have it look for the first tag titled [Bronze], and from there have it look for [Plate Mail]?
It needs to read to the first tag alone because I will have 8 different references to [Plate Mail] for the different materials used.
We are just trying to help you make a file so you can search what you want easily.
You need to make it so something is unique so it's easy to find. Why not create it simple at the start rather than trying to make it difficult?
-
The file is very simple, based on the variables I'm using in the game.
BodyArmourType and BodyArmourMetal are two distinct variables, so I just use something like this in the text file:
[Bronze]
[Chain Mail]
DefensePoints=1
Cost=375
[Plate Mail]
DefensePoints=2
Cost=500
[Plate Legs]
DefensePoints=2
Cost=400
[Square Shield]
DefensePoints=2
Cost=350
[Iron]
[Chain Mail]
DefensePoints=1
Cost=375
[Plate Mail]
DefensePoints=2
Cost=500
[Plate Legs]
DefensePoints=2
Cost=400
[Square Shield]
DefensePoints=2
Cost=350
[Kite Shield]
DefensePoints=3
Cost=450
And on and on and on for the rest of the items. I don't want to have to do a bunch of string combinations to get what I'm looking for, I just want to search for the line that matches BodyArmourMetal and then match up BodyArmourType to find what I'm looking for.
-
Hello, this is one way you can read the data from the file!
For sMaterial send "[Bronze]" or "[Iron]" and for sItem "[Item name]" ex: "[Plate Legs]"
Code:
Public Sub GetData(sMaterial As String, sItem As String)
Dim sTemp As String
Dim iDP As Integer, iCost As Integer
Dim bGotIt As Boolean 'Has i gathered the info?
Open "c:\data.ini" For Input As #1
Do While Not EOF(1)
Input #1, sTemp
If InStr(1, sTemp, sMaterial) Then
Do While Not EOF(1)
Input #1, sTemp
If InStr(1, sTemp, sItem) Then
Input #1, sTemp
'"DefensePoints=" = 14 char's so skip 14!
iDP = CInt(Mid(sTemp, 15, Len(sTemp) - 14))
Input #1, sTemp
'"Cost=" = 5 char's so skip 5!
iCost = CInt(Mid(sTemp, 6, Len(sTemp) - 5))
bGotIt = True
Exit Do
End If
Loop
End If
Loop
Close #1
MsgBox sMaterial & vbCrLf & sItem & ":" & "DP: " & iDP & vbCrLf & "Cost: " & iCost
End Sub
This function is case sensitive. But to fix that add some UCase()