Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Forged on June 25, 2004, 11:19 AM

Title: Random Generator
Post by: Forged on June 25, 2004, 11:19 AM
I am hosting a war3 Tourny and need a program that can take a list of maps and randomlly spit one out.  The problem is I have no idea how to do this, I assume it has something to do with arrays but for the most part I am clueless.  Can someone please help me?
Title: Re:Random Generator
Post by: Spht on June 25, 2004, 11:55 AM
Quote from: Forged on June 25, 2004, 11:19 AM
I am hosting a war3 Tourny and need a program that can take a list of maps and randomlly spit one out.  The problem is I have no idea how to do this, I assume it has something to do with arrays but for the most part I am clueless.  Can someone please help me?

You can use Dir to get the filename of each map in the maps folder while loading them into a string array.  When finished, you can then use the formula Int((upperbound - lowerbound + 1) * Rnd + lowerbound) to pick out a random map filename from the string array.  upperbound being UBound result and lowerbound being LBound result of the string array.
Title: Re:Random Generator
Post by: Forged on June 25, 2004, 02:18 PM

Public Sub GetMap()
Dim Random As Integer
Dim Maps As String
Dim count As Integer
Dim Pick As String
Maps = Dir(App.Path & "/maps.txt")

Open Maps For Input As #1
    Do
        Input #1, Pick
            count = count + 1
        Loop Until EOF(1)
        Close #1

Randomize
Random = (Rnd * count) - 1
If Random <> 1 Then
   Random = Random - 1
End If
Open Maps For Input As #1
 Do
   Line Input #1, Pick
   Random = Random - 1
   Loop While Random <> 0
   Form1.Text1.Text = "Use " & Pick

End Sub


It picks the first map on the list -_-
Title: Re:Random Generator
Post by: Stealth on June 25, 2004, 05:37 PM
Did you listen to a word Spht said? He even gave you the random selection formula.