random number to a certain event depends ont the number

Started by mangamaniacs2064 on

Topic category: Help with MCreator software

Joined Jul 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
random number to a certain event depends ont the number

okay heres is what i tried...

 

set nbt number tag "catchfish" of block at x y z random0,1 x 6 if it has tile entity

 

if nbt number tag "catchfish" of block at x:  x y z if it has tile entity = 2 or nbt number tag "catchfish" of block at x:  x y z if it has tile entity = 6

do send to chat to all players:"fish catched!!!"

 

can you show me why it doesnt work.

Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
random[0,1] is not an…
Sat, 10/12/2019 - 13:43

random[0,1] is not an integer (whole) number. It's a float/decimal number. Checking whether such a number is equal to something is very bad practice.

Your procedure does work and generates a number between 0 and 6. However here are some of the possible outcomes:

5,245642 - 3,723453 - 52,64223 - 6

You can see why there's such a minute chance of catchfish ever being equal to 2 or 6. When working with floating point numbers, try something like:

if random[0,1] < 0.2

do...

which would give you a 20% chance at catching the fish. If you do want whole numbers, make sure to use ROUND to round the number. (Rounding up/down is also good practice when working with chance, as simply using round causes the 0 and highest number to only have half of the chance of appearing compared to any other number in between)

Joined Jul 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it worked out thanks!!!
Sat, 10/12/2019 - 16:55

it worked out thanks!!!