ID:178995
 
how can I use a for(Mobs here) to get a random number, where that number is between 1 and that player's var, then compare it agains't many other mobs random number? I've got the finding part, but I can't figure out how to compare them...

Please help, because I am reaching my limits in BYOND with my current project, which is a good thing.

Note: I have been through Help, and I think I may have to use a list. Is this right? and if so, how do lists work?
Look up:
rand

Then it depends on how you want to compare them. We'd need more specifics.
Airson wrote:
how can I use a for(Mobs here) to get a random number, where that number is between 1 and that player's var, then compare it agains't many other mobs random number? I've got the finding part, but I can't figure out how to compare them...

That's a good description, because it practically writes the code for you.

You know how to use for(), and how to use if(). To compare two numbers, it would be:

if (first_num == second_num)

or whatever. The == means "if they are equal". You could also say:

if (first_num < second_num)

So iterate through the list of mobs, and for each one in the list do the check.
In response to Deadron
I think his question is more on how to use the results of the random number to organize the mobs in a list or something of that nature by comparing the values. An example would be to give them a random speed value then organize them in order of greatest to least speed.

Maybe I'm over complicating his question, I guess that means I should be quiet and let him speak for himself :p
In response to English
That's exactly what I was asking for. I need to get a list of all racers, along with their number. then, I need to weed out the lowest one, so organization would probably be from greatest to least. Then, I need to repeat this process until only one person is left.

I'm at school now, but I'll post my code later to let ya'll take a look...

Airson

P.S. I know what rand() does, don't worry.
In response to Airson
Once you have your list all you will need to do is assign a variable to the lowest speed and then delete it. good job though learning the basics before you hit the boards.
Airson wrote:
how can I use a for(Mobs here) to get a random number, where that number is between 1 and that player's var, then compare it agains't many other mobs random number? I've got the finding part, but I can't figure out how to compare them...

I'm a little lost on what you mean by that. I understand this much (and this is how you probably should have stated it): For every mob in a list, I want to assign a random number, and then I want to compare the mobs' numbers. But what kind of comparison did you have in mind? A sort?

Note: I have been through Help, and I think I may have to use a list. Is this right? and if so, how do lists work?

You're likely to need a list, yes--if for no other reason than that you probably don't want to create a new var in each mob just to hold the random result.
var/list/L=list()
for(var/mob/M in themobs)
L[M]=rand(1,M.myvar)
... // do the comparison here, whatever it is

With a more complete description of your problem I could offer more advice. If you're looking to sort them... well, sorting an associative list can be difficult, because Dantom have yet to add the oft-requested Insert() and Swap() procs to lists. Hint, hint. Hint hint hint hint.

Lists are fairly easy to use, so the reference will help you there. The code I've posted here uses an associative list; once you learn a little about ordinary lists, things like L[1]=3 and L[2]="monkey", and L+=the_grapefruit, you'll be able to move on and use the full power of lists in BYOND. I recommend you read my BYONDscape article (now available in the archives), Learn To Love Associative Lists. First, familiarize yourself just a little with regular lists, so you have some solid footing before you go to the next step.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
With a more complete description of your problem I could offer more advice. If you're looking to sort them... well, sorting an associative list can be difficult, because Dantom have yet to add the oft-requested Insert() and Swap() procs to lists. Hint, hint. Hint hint hint hint.

I have an insert proc in ListHelp which should keep associations, but it would be nice to have such things outside of DM with whatever speed enhancement that implies.
In response to ACWraith
ACWraith wrote:
I have an insert proc in ListHelp which should keep associations, but it would be nice to have such things outside of DM with whatever speed enhancement that implies.

Given the lookup requirements for a swap, a built-in proc would probably save quite a bit of time (proportionally speaking), and likewise for an insert.

Lummox JR
In response to Lummox JR
alrighty...here's the deal. for those of you who don'tunderstand what I am saying, and most of you probably don't, which is my fault, I'll try to put this into english...

Each player has a var named cycle_type. This var could be anything from 2-20, but can only be even. During the race, I would get a random number between one and their var for each mob. Then, I would need to find the lowest one. If there is a tie, I would need to get another number for just the ones that tied. Then, of those that tied, I would delete the lowest one from the race. If none tied, I would delete the lowest. I would need to repeat this until all except one was deleted.

I know how to get the random numbers but here's what happens-
for(var/mob/M)
var/speed = rand(1,M.speed)

I'm sure you can see a problem in this if I need to keep the people who are in and their speeds; var/mob/M would be lost when the For() looped.

Well, hope I helped in my quest for help...I guess my system is easier to show with dice in front of someone''s face.
In response to Airson
Airson wrote:
alrighty...here's the deal. for those of you who don'tunderstand what I am saying, and most of you probably don't, which is my fault, I'll try to put this into english...

Each player has a var named cycle_type. This var could be anything from 2-20, but can only be even. During the race, I would get a random number between one and their var for each mob. Then, I would need to find the lowest one. If there is a tie, I would need to get another number for just the ones that tied. Then, of those that tied, I would delete the lowest one from the race. If none tied, I would delete the lowest. I would need to repeat this until all except one was deleted.

I know how to get the random numbers but here's what happens-
for(var/mob/M)
var/speed = rand(1,M.speed)

I'm sure you can see a problem in this if I need to keep the people who are in and their speeds; var/mob/M would be lost when the For() looped.

Ah. Now this is easy enough to do.
var/list/lowest=list()
var/lowN=0
if(!carsinrace.len) return
for(var/mob/car in carsinrace)
var/N=rand(1,car.cycle_type)
if(lowN<N)
if(lowest.len) continue // this isn't the loser
else lowN=N
else if(lowN>N)
lowN=N
lowest=list() // clear the list
lowest+=car
if(lowest.len) RemoveCarFromRace(pick(lowest))

Hope that helps.

Lummox JR
In response to Lummox JR
well, I have a strict policy- "If I don't understand how it works, I won't use it until I do." So I bet you can guess what I'm gonna spend my week doin...
In response to Airson
Airson wrote:
well, I have a strict policy- "If I don't understand how it works, I won't use it until I do." So I bet you can guess what I'm gonna spend my week doin...

This is a decent policy with snippets and demos. It is not always a good policy with libraries. Libraries are black boxes. You send something in and get something out, but it's none of your business how it happens. How it happens might even change on the next update.

Don't get me wrong. For stuff pasted in forums, it's generally a good idea.