Else If Statement with Procedure Calls and Random Number Generators call twice?

Started by RedRaspy156 on Mon, 05/23/2022 - 22:10

Topic category: Troubleshooting, bugs, and solutions

Last seen on 20:54, 24. Jun 2022
Joined Jul 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Else If Statement with Procedure Calls and Random Number Generators call twice?
Mon, 05/23/2022 - 22:11 (edited)

I've been having difficulty trying to solve why sometimes this else if calls a separate procedure twice.

Could someone possibly find a way to fix this or change the way it is setup?

Here is an image:

Else if statement using number generators to call separate procedures

Edited by RedRaspy156 on Mon, 05/23/2022 - 22:11
Last seen on 00:23, 25. Jun 2022
Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Hey, I can't view the image…
Mon, 05/23/2022 - 22:54

Hey, I can't view the image. It's probably because you copy-pasted it, sadly, it doesn't save that way. Could you upload it to imgur or ibb?

Last seen on 03:41, 25. Jun 2022
Joined Apr 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
The "Random [0, 1]" blocks…
Wed, 06/22/2022 - 11:50

The "Random [0, 1]" blocks are independent of one another, meaning they will all run in succession. You have to store the result of one "Random [0, 1]" block to a local variable before you use the random number, then assign ranges to each if-else statement. For example, if you have 4 possible outputs, you can have the else-if conditions as follows:

If (0 >= [local var] < 0.25)
    output 1
else if (0.25 >= [local var] < 0.5)
    output 2
else if (0.5 >= [local var] < 0.75)
    output 3
else
    output 4

These ranges can all be equal, as shown in the above example, or each range can be different:

If (0 >= [local var] < 0.05)
    output 1
else if (0.05 >= [local var] < 0.4)
    output 2
else if (0.4 >= [local var] < 0.88)
    output 3
else if (0.88 >= [local var] < 0.94)
    output 4
else
    output 5

Make sure that you set a local variable to a random number prior to using it - do not use the random block for the examples I have given.