|
-
Apr 20th, 2004, 02:54 PM
#1
-
Apr 20th, 2004, 03:15 PM
#2
Frenzied Member
I would build it like an Ini file instead..
[Armour]
Bronze1=Platemail
Bronze2=Chainmail
etc..
-
Apr 20th, 2004, 03:47 PM
#3
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.
-
Apr 20th, 2004, 05:26 PM
#4
PowerPoster
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
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Apr 21st, 2004, 08:03 AM
#5
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.
-
Apr 21st, 2004, 08:25 AM
#6
Frenzied Member
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?
-
Apr 21st, 2004, 10:05 AM
#7
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.
-
Apr 22nd, 2004, 12:42 PM
#8
Member
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()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|