Finding the variable with the highest value.

● ARCHIVED · READ-ONLY
Started by Bill5000 6 posts View original ↗
  1. I have a set of variables that once an event is triggered, all roll random numbers. (Each variable has many possible modifiers so using one variable, while simpler, is not really possible)

    After they all roll random numbers, I need a way to set another variable to match the value of the variable that rolled the highest.

    For example:

    Variable 1 rolled 10
    Variable 2 rolled 20
    Variable 3 rolled 15
    Variable 4 is not random, but instead equals the highest value of the previous variables (In this example, Variable 2)

    What I need is a way to set Variable 4 to equal 20 as well, as it was the highest roll. I know I could use conditional branches to compare all of the values, but that gets unorganized quickly, and makes tweaking certain things in the future difficult, considering I have many variables that are going to be rolled.

    Is there a simple, clean, script I could use?
  2. Bill5000 said:
    I have a set of variables that once an event is triggered, all roll random numbers. (Each variable has many possible modifiers so using one variable, while simpler, is not really possible)

    After they all roll random numbers, I need a way to set another variable to match the value of the variable that rolled the highest.

    For example:

    Variable 1 rolled 10
    Variable 2 rolled 20
    Variable 3 rolled 15
    Variable 4 is not random, but instead equals the highest value of the previous variables (In this example, Variable 2)

    What I need is a way to set Variable 4 to equal 20 as well, as it was the highest roll. I know I could use conditional branches to compare all of the values, but that gets unorganized quickly, and makes tweaking certain things in the future difficult, considering I have many variables that are going to be rolled.

    Is there a simple, clean, script I could use?

    Code:
    for(var i = 1; i <= 3; i++) {
     $gameVariables.setValue(i, Math.randomInt(100));
    } $gameVariables.setValue(4, Math.max($gameVariables.value(1),$gameVariables.value(2),$gameVariables.value(3));
  3. Wow, fast reply. Thank you!

    I had to add a ")" to the end of the bottom line, before the semi colon or else I got an error.

    It functions exactly as I need, except for some reason variables after being rolled are getting outcomes that should be impossible.

    For example one variable is set to roll random 1 to 40, but ended up with a value of 76. All of the variables that are being randomly rolled are getting these kinds of results.

    Sorry, my knowledge of scripting is minimal. So do you know what I could be doing wrong?
  4. Bill5000 said:
    Wow, fast reply. Thank you!

    I had to add a ")" to the end of the bottom line, before the semi colon or else I got an error.

    It functions exactly as I need, except for some reason variables after being rolled are getting outcomes that should be impossible.

    For example one variable is set to roll random 1 to 40, but ended up with a value of 76. All of the variables that are being randomly rolled are getting these kinds of results.

    Sorry, my knowledge of scripting is minimal. So do you know what I could be doing wrong?

    Math.randomInt(100) <<< change this number to the Maximum value of Outcome
  5. Oh, I see how that works now thank you very kindly for your help!
  6. This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.