Posts ID:926656 Favorites Creations
ID:926656

(See the best response by Kaiochao.)
Am I correct in assuming the following?

 ```if(prob(80)) //There is an 80% chance that A //A will occur.else //If it does not, if(prob(80)) //there is an 80% chance that B //B will occur. else //If it does not, if(prob(80)) //there is an 80% chance that C //C will occur. else //If it does not, D //D will occur. ```

The idea would be to use this to determine ranges of item stats and item rarity. Would it work? Is there a less messy way to do this? Thanks for any help.
 ```if(prob(80)) //There is an 80% chance that A //A will occur. returnif(prob(80)) //there is an 80% chance that B //B will occur. returnif(prob(80)) //there is an 80% chance that C //C will occur. returnD //D will occur. ```

That would be how I handle that~
Just return if the condition is true after you do what you want within it, then move to the next one, as the next can only run if the first is false.
That could work; pick() is a alternative to this however.

But I think I'd personally do something with while().

 ```var/rarity=1while(rarity<10) if(prob(80)) break else rarity++item.rarity=rarityitem.effect+=rarity ```
 #3 Aug 12 2012, 11:25 am In response to Kitsueki (#1) Best response Actually, the if-else chain is better. It doesn't stop the rest of the procedure. Of course, he could've put the ifs on the same line as the elses, to save tabs.
In response to Kitsueki (#1)
Kitsueki wrote:
 ```>> if(prob(80)) //There is an 80% chance that> A //A will occur.> return> if(prob(80)) //there is an 80% chance that> B //B will occur.> return> if(prob(80)) //there is an 80% chance that> C //C will occur.> return> D //D will occur.> ```

That would be how I handle that~
Just return if the condition is true after you do what you want within it, then move to the next one, as the next can only run if the first is false.

Wouldn't that allow for multiple selections though? Like, there's an 80% chance that all of the above will be run? I only want to run one of them. Or maybe I'm not clear on what return does cause I never use it. lol

NNAAAAHH wrote:
That could work; pick() is a alternative to this however.

But I think I'd personally do something with while().

 ```> var/rarity=1> while(rarity<10)> if(prob(80))> break> else> rarity++> item.rarity=rarity> item.effect+=rarity> ```

The problem with that, is these if statements I'm referring to actually set the item rarity based on stats, using a simple calculation system I'm working on. So I wouldn't be able to use the rarity to determine the stats because stats come first.
You intend to set the rarity based on the stats? I'd call this stat setting in on proc, and then assign the rarity in that case. 'return' stops the procedure. To be more specific, it forces the procedure to return. If you give it something to return, the result of the procedure will be whatever you return, so this for example..

 ```proc true_proc() return 1mob verb test_proc() if(true_proc()) world << 1 else world << 0 ```

Would output 1, because true_proc() returns 1, which evaluates the condition to be true.

Using return in this case is just a method to stop the procedure so nothing else in it runs.
Going with Kaiochao's suggestion, this could be the method to do what you want, I believe.

 ```proc/set_stats() if(prob(80)) //There is an 80% chance that A //A will occur. else if(prob(80)) //there is an 80% chance that B //B will occur. else if(prob(80)) //there is an 80% chance that C //C will occur. else //If it does not, D //D will occur.proc/set_rarity() set_stats() // do stuff to set rarity ```

Hope this helps!
 #6 Aug 12 2012, 11:45 am Alrighty, thanks! Cheers to about a years worth of coding *sigh*... Makes me wish I had a team.
I would suggest reading this for a quick list of different ways to do probabilities:
http://www.byond.com/forum/?post=899306#comment2833013

I also think the pick() method is the most configurable, although you need a constant number of choices.

Also, keep in mind:
 ```if(prob(80)) // 80% chance // Aelse if(prob(80)) // ***16%*** chance (20% * 80%) // B ```
In response to DarkCampainger (#7)
DarkCampainger wrote:
I would suggest reading this for a quick list of different ways to do probabilities:
http://www.byond.com/forum/?post=899306#comment2833013

I also think the pick() method is the most configurable, although you need a constant number of choices.

Also, keep in mind:
 ```> if(prob(80)) // 80% chance> // A> else if(prob(80)) // ***16%*** chance (20% * 80%)> // B> ```

Ok thanks. and yeah that's kinda the idea

Wait a minute... I need a calculator... lol

So I would need up to E to make items with a decent rarity. Cool.