Results 1 to 8 of 8

Thread: text file searchout???

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Arrow text file searchout???


    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...

    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!

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    I would build it like an Ini file instead..

    [Armour]
    Bronze1=Platemail
    Bronze2=Chainmail


    etc..

  3. #3

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    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.

  4. #4
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    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.


  5. #5

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    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.

  6. #6
    Frenzied Member
    Join Date
    May 2003
    Location
    So Cal
    Posts
    1,564
    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?

  7. #7

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465
    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.

  8. #8
    Member
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    53
    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()
    You are reading my signature! :-)

    My WIP site

    Three Great bands:
    Beseech
    Meshuggah
    Opeth

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width