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. 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.
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.
> > 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().
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 1
mob 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. elseif(prob(80)) //there is an 80% chance that B //B will occur. elseif(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
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.