Blockland Forums > Modification Help

Randomization

Pages: << < (2/2)

phflack:


--- Quote from: MegaScientifical on December 15, 2010, 06:41:18 PM ---
--- Code: ---switch(getrandom(1, 3)) {
case 1:
function1(%blah);
case 2:
function2(%blah);
case 3:
function3(%blah);
}
--- End code ---

Why did you put breaks in there, phflack? You also forgot spaces in the case areas and such. Not that you aren't smart, but keep that in mind. :)

--- End quote ---
oops about the spaces, but the break; is needed i thought, at least in C++, as it would then continue to the next statements
i figured it was the same, so i added them in my script with the same style, and it worked, so i figured it was the same

--- Quote from: Jasa 12265 on December 15, 2010, 07:53:50 PM ---I was hoping on making some more common than the other.

--- Code: ---function Function()
{
if(getRandom(1,10) >= 7)
{
Common()
}
if(getRandom(1,10) <= 8)
{
LessCommon()
}
if(getRandom(1,10) == 10)
{
BarelyCommon()
}
}

--- End code ---
But that would call multiple. How would I make it so after one returned true it stopped there?


--- End quote ---
you're getting a new random number each time

also, is it possible to have like case 1-5 or no?

Chrono:


--- Quote from: phflack on December 16, 2010, 04:02:54 PM ---
also, is it possible to have like case 1-5 or no?

--- End quote ---
No and I already fixed it all and explained why it was broken.

MegaScientifical:


--- Quote from: phflack on December 16, 2010, 04:02:54 PM ---... but the break; is needed i thought, at least in C++, as it would then continue to the next statements...

--- End quote ---

Even if that's true, It's already defined as a certain number. Going into the other checks won't make a difference since it isn't those numbers.

lordician:


--- Quote from: MegaScientifical on December 16, 2010, 11:49:20 PM ---Even if that's true, It's already defined as a certain number. Going into the other checks won't make a difference since it isn't those numbers.

--- End quote ---
Right, but in Java and C++ it would do all of the ones that came after it.
It's silly, but it really happens.
So i get why he said that and i don't know if the same applies to Torquescript.
I guess so.

Pages: << < (2/2)

Go to full version