| Blockland Forums > Modification Help |
| Randomization |
| (1/2) > >> |
| Jasa 12265:
How would I get a script to call a random function. I was thinking getrandom(function1 , function2 , function3) or something like that. |
| phflack:
switch(getrandom(1,3)) { case1: lalalala; break; case2: lalalala; break; case3: lalalala; break; } that would call a random lalalala, #1-3 |
| MegaScientifical:
--- 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. :) |
| Jasa 12265:
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? |
| Chrono:
--- 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 --- Do this --- Code: ---function Function() { %r = getRandom(1,10); if(%r == 10) { BarelyCommon() } else if(%r <= 7) { Common() } else if(%r >= 8) { LessCommon() } } --- End code --- The problems in yours include: 10's if would never get called from the bottom. Wrong < and > Lacking else, which only calls one of the ifs. And it's getting a new random number for each if statement. |
| Navigation |
| Message Index |
| Next page |