Page 1 of 1
no repeat random
Posted: Fri Jun 29, 2007 6:53 pm
by ViPER
i have an array of 10 items that i access randomly.
Code: Select all
level.mylist = makeArray
"one" "1"
"two" "2"
"three" "3"
"four" "4"
"five" "5"
"six" "6"
"seven" "7"
"eight" "8"
"nine" "9"
"ten" "10"
endArray
how can i make so they do not repeat untill all 10 have been accessed ? the second time around can be the same random order or a new random order it doesnt matter.
Posted: Sat Jun 30, 2007 7:45 am
by lizardkid
make a new list every time you take a number; it's how other scramblers do it.
You have the array of numbers. let's say it has 10 of them. You make a loop to take a random number from it and do something with it. Then you make a new list that holds the 9 remaining numbers. Store this list under the name of the list that had the original 10 numbers, and continue. So sorta like this in psueducode.
Code: Select all
//level.mylist has the numbers already.
local.number = level.mylist[random(0 to mylist.length)]
//do stuff with local.number
for(local.i = 0, local.i < mylist.length, local.i++)
if(local.i == local.number)
continue
else
local.list2[i] = level.mylist[i]
Posted: Sat Jun 30, 2007 10:38 am
by bdbodger
To access your list you use level.mylist[1][1] for the first item "one" and level.mylist[1][2] for the "1" so add a third value level.mylist[1][3] and make a 0 when it is used make it a 1
Code: Select all
Random_test:
level.mylist = makeArray
"one" "1" 0
"two" "2" 0
"three" "3" 0
"four" "4" 0
"five" "5" 0
"six" "6" 0
"seven" "7" 0
"eight" "8" 0
"nine" "9" 0
"ten" "10" 0
endArray
level.numbers = 10
for(local.i = 1;local.i<= 10;local.i++)
{
local.num = waitthread picknum
iprintln_noloc "The number is " local.num
waitframe
}
end
picknum:
local.check = 1
while(local.check == 1)
{
local.random = randomint(level.mylist.size)+1
local.check = level.mylist[local.random][3]
if(local.check == 0)
{
level.mylist[local.random][3] = 1
level.numbers--
if(level.numbers == 0)
{
for(local.i=1;local.i <= 10;local.i++)
{
level.mylist[local.i][3] = 0
}
level.numbers = 10
}
}
}
end level.mylist[local.random][1] // or level.mylist[local.random][2]
The result
LOCALIZATION ERROR: 'Press Use(f) to follow a player.' does not have a localization entry
The number is ten
The number is five
The number is eight
The number is seven
The number is one
The number is nine
The number is six
The number is three
The number is two
The number is four
----- Server Shutdown -----
Resets it's self when all the numbers have been used
Posted: Sun Jul 01, 2007 9:19 pm
by ViPER
Thanks guys,
This is for the domination mod, I think im going with Bodger's method but unfortuneatley I dont have time to get it in the release with proper testing and everything, so i will work it in a later update script.