Started by ThePixelUnknown
on Sat, 07/21/2018 - 02:21

**Topic category:** Help with MCreator software

Is there a way to make a block that can pick from a random value scale (AKA a number from 1-3) with the procedure system. I did see that there was a random number option for the "π" math block, but the scale was stuck at 0-1 and I don't know how to change it. If anyone knows how to change it, please say so.

Thank you for responding in advance.

You can multiply random number by 3 to get numbers in the range from 0 to 3.

I see. Well, thank you. I would've never figured that out.

So, I tried doing this with a block as I wanted it to randomly drop one item or another when you right-click it. I multiplied the random number by three and had three different outcomes, depending on what the random number would be. Well, this didn't work as nothing spawned from the chest. I'm sure I did the code correctly, but it seemed the random number didn't go through. Please help!

Try to print the value so you can actually see it.

I was thinking about doing that, but I'm not sure how to print a variable into chat. Do you have a sample you could show, if it isn't too much trouble? Thanks in advance.

If you take the code approach, it is

System.out.println(STUFF_TO_PRINT);(you will most likely want to save the generated value to a local variable and then use it to both print and the stuff you want), if you chose to use the procedure system, well , only I can tell you is that there deffinitely is some sort ofprocedure block , but as I have not used theprint to consoleevent/proceduresystem for like 3 years , I can not tell anything more exact now.Okay, thank you! I will try this soon. Thank you for the support and sorry if it's a hassle for how long this is taking.

You can use the print block in the Text category of the procedure system.

Okay, tried doing the block method. It did work, however, the random number had many decimals after it, which is probably why nothing would happen when I right-clicked the block since I was trying to compare the random number variable to specific whole numbers. I could use "<" or ">" signs to specify a range, but that would not work for three or more different outcomes. Any way to convert these decimals to whole numbers so I could use them for whole-numbered outcomes? Thanks again, by the way

If you used equal condition instead of the others, then yes - that is the reason, as I am like 98% sure that

MCreatorusesMath.random()for generating a random decimal in range0 - 1 (both inclusive), or if not this one , then eitherRandom#nextFloat()orRandom#nextDouble()(which both again generate decimal in the same range).That is actually why multiplying the result by your desired maximal value gives you all the numbers between 0 and the value.

Example (

)the maximal value = 100.0*10 = 01.0*10 = 100.625*10 = 6.250.97*10 = 9.7etc...Now, how can you solve this? First this sentence

is totally wrong. The simplest (but not the only) way to use these is checking in reverse order, so for a scenario, with

maximal value 3:isX >= 2--- do stuff , else continue to next checkisX >= 1--- do stuff, else do some another stuff (or you can use another checkX >= 0)If you want to use the rounding approach, well you can, even though I think that it is the worst one in terms of performance. You have several options here, each one of them is a bit different:

Math.round()- round in a way you would expect - so less than 0.5 down, 0.5 or greater upMath.floor()- always rounds down (hence the name then name "floor")Math.ceil()- always rounds up (hence the name name "ceil")int typecast (basically you add(int)before the value so you cast it to int) - same asMath.floor()In case that you do not want to use the greater than or equal check approach and that you do not want (hopefully) to use the round approach, you can just generate the number as an int from start (and therefore as a non-decimal number) , by using

Random#nextInt(). This function has an optional parameter of type int. Without the paramter the method returns a value of a whole number in range0-1 (so 0 or 1), if you pass some argument , it generates a number in a range0 - X (exclusive), so if I pas a number 4 , it will return a whole number in range0-3.Okay, I did not about putting the "greater than or equal to" in reverse order. I believe that just solved my issue (hopefully!). Thank you for guys for sitting through this long stream of comments for a small question like this!

Thank you guys*

I get 0-3 is there a way I can make it 1-3? getting 0 from my Blue Berry Bush doesn't make sense so help would be awesome.