ID:174838
 
If you have a random number generator set up like:
atom/movable
var
random

mob/verb/randomnumber()
set name = "Random Number"
usr.random = rand(1,50)
if (usr.random == 1) usr << "You get number one!"
etc.

How would you go about making it so that the same number can't be picked twice, and if it is to redo the generation> (Keep in mind it has to be able to revert to no numbers picked, too).


I guess you could probably make a list, and every time it generates a number, check if it's in the list. If not, add it to the list and use it for whatever you're doing. If it is in the list, keep generating numbers until it gets one that isn't in the list, then use it. To reset, just clear the list. I think that's possible, at least.
In response to Mertek
Hmm...I'm not quite sure how I'd do that...I just woke up and thinking about lists makes my head hurt...any other less painful ideas?

.::DBHavenMaster::.
In response to DBHavenMaster
I'm trying it with global var's but I'm having trouble setting it up. I want it to be something like:
var/a // 50 var's...just to be sure
usr.random = rand(1,50)
if (usr.random == 1) usr << "You pick one!"
a = 1 // not sure how to set it automatically, but then I'll run a check on the var's to see if it's been chosen before, and if so to draw again.

if (a == usr.random)//would I need one for every variable? or could I have it check them all?


Thanks in advance,
.::DBHavenMaster::.

In response to DBHavenMaster
I guess you could do it with variables, but that is way too messy to run through 50 of them and check each one for your number. Read up on lists and it will be much, much easier. You do NOT want to do it with variables, trust me.
In response to Mertek
Mertek wrote:
I guess you could probably make a list, and every time it generates a number, check if it's in the list. If not, add it to the list and use it for whatever you're doing. If it is in the list, keep generating numbers until it gets one that isn't in the list, then use it. To reset, just clear the list. I think that's possible, at least.

At least use pick() to go through the list and pick one of the remaining numbers. But before you do that, check to see if there is anything left in the list so you don't get an error, check list.len.
In response to DBHavenMaster
I'm trying to set up a cut proc like this:

proc/NamedProc()
if(usr.variable > 20)
world << "[src]'s variable is over 20!"
Cut (start=1,end=0)

I've also tried

proc/NamedProc()
if(usr.variable > 20)
world << "[src]'s variable is over 20!"
Cut (chosen(start=1,end=0))

and

proc/NamedProc()
if(usr.variable > 20)
world << "[src]'s variable is over 20!"
chosen Cut (start=1,end=0)

None of them work.

How do I set up a cut proc properly?

Thanks,
.::DBHavenMaster::.
In response to Mertek
Personally I suspect there is probably a better way to do whatever he's trying to do in the first place. But since I have no idea what that is, I can't really suggest anything.