• Welcome to Valhalla Legends Archive.
 

Random Generator

Started by Forged, June 25, 2004, 11:19 AM

Previous topic - Next topic

Forged

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?
QuoteI wish my grass was Goth so it would cut itself

Spht

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.

Forged


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 -_-
QuoteI wish my grass was Goth so it would cut itself

Stealth

Did you listen to a word Spht said? He even gave you the random selection formula.
- Stealth
Author of StealthBot