Need Help adding variables + Checking minimum

I have a small problem trying to add some variables together as it gives me the following error message.
Code:
◆Control Variables:#0009 d6_num1 = Random 1..6
◆Control Variables:#0010 d6_num2 = Random 1..6
◆Control Variables:#0011 d6_num3 = Random 1..6
◆Control Variables:#0012 d6_num4 = Random 1..6
◆Script:stat = d6_num1 + d6_num2 + d6_num3 + d6_num4;
◆Text:None, Window, Bottom
:    :\V[0013]
You can not access game variables by name in script, because those names only exist in the editor.
And "stat" as a variable will be deleted as soon as the script command is complete anyway.

Your best option so far would be to use a series of control variable commands to add those numbers together.
You could use something like this though:

script: $gameVariables.setValue(13, $gameVariables.value(9) + $gameVariables.value(10)) etc.
Control Variables has a += function, so you can ADD the random number to the existing number
\v[0013] is probably going to give you an error. You never use leading zeros.

Control Variables: 13: stat = Random 1..6
Control Variables: 13: stat += Random 1..6
Control Variables: 13: stat += Random 1..6
Control Variables: 13: stat += Random 1..6
Text: \v[13]

However, 4 lots of random numbers between 1 and 6 is just going to give you a random number between 4 and 24. So why not just put

Control Variables: 13: stat = Random 4..24
Text: \v[13]
@Shaz that has not the same probabilities. 4d6 has the highest probability for a result 14, with 4 and 24 being a lot less likely. Your variant would give all numbers the same probability.
doesn't Random 1..6 give an equal chance to every number? Doing it 4 times would give an equal chance to every number, 4 times.
Thank you I will try some of the advice here. Is there a way to check which of said random numbers is the lowest? I am going to add a 5th one and they do need to be separate from one another.
EDIT:This worked thank you very much.
Code:
◆Script:$gameVariables.setValue(14, $gameVariables.value(9) + $gameVariables.value(10) + $gameVariables.value(11) + $gameVariables.value(12) + $gameVariables.value(13))
Shaz, yes a single rnd always gives same probabilities, but not added rnds.
Example is how you get a 5 from d6 + d6 + d6 + d6. This could be a 1+1+1+2 or a 1+1+2+1 or a 1+2+1+1 or a 2+1+1+1. As a result, 5 is four times as often than 4 ( which can only result from 1+1+1+1).
This may be asking a heck of a lot but is there a way to determine which number would be the lowest? Also how would I create an ElseIf statement in the coding?
Unfortunately RMs do not contain automatic sorting, you would have to program in a sorting algorithm yourself.

Elseif is nested conditional branch. The else branch of a conditional branch can be activated in the command window of the conditional branch (checkbox at bottom), and then place another conditional branch command inside the else branch.
Would there be any easy way I could check each of the variables values after they are rolled? Edit: Such as;
Code:
◆Script:[$gameVariables.value(9), $gameVariables.value(10), $gameVariables.value(11), $gameVariables.value(12), $gameVariables.value(13)].min

I was asking if I could get around creating another command in the conditional branch outside the original one. I guess not so I will continue doing it that way.
Only by conditional branch after each roll
@Andar would the edit I made work?
edit: Or making the min another variable set as that number aka this
Code:
◆Script:$gameVariables.setValue(20, $gameVariables.value(9), $gameVariables.value(10), $gameVariables.value(11), $gameVariables.value(12), $gameVariables.value(13).min)
It seems it is not working as I get varying different results where it seems to add to the minimal value. Unless it saves it from previous tries.
attempt 1
1 #09
3 #10
5 #11
5 #12
3 #13
addition all 17
addition expected 16 result 16

attempt 2
4 #9
3 #10
4 #11
2 #12
6 #13
addition all 19
addition expected 17 result 15

attempt 3
4 #9
1 #10
5 #11
1 #12
1 #13
addition all 12
addition expected 11 result 8

attempt 4
5 #9
2 #10
3 #11
6 #12
5 #13
addition all 21
addition expected 19 result 16
These were the results I got.
Edit: @Andar @Shaz can anybody help me? it seems to only subtract the first roll from the total.
.
*bump* sorry
Just FYI, his/her name is Andar, not Ander for when you tagged him/her.

Code:
◆Script:$gameVariables.setValue(20, $gameVariables.value(9), $gameVariables.value(10), $gameVariables.value(11), $gameVariables.value(12), $gameVariables.value(13).min)
It's hard to tell what you are trying to do - what is that code supposed to do?

Throwing a ".min" on something won't automatically work, it has to follow the rules of JavaScript. Here is the syntax for the Min function.

By analyzing your 4 attempts I am guessing that you want to roll 5 dice and ignore the value of the lowest die.
But, in your 4 attempts what is happening instead, is the 1st die is always being ignored, probably because the syntax is not correct.

Here is an example on how to implement such a system:

Spoiler: Example Event Page
ExampleRoll.png

The script part is cut off in the screenshot so I copied it below.
Spoiler: Lowest
Code:
Math.min($gameVariables.value(41), $gameVariables.value(42), $gameVariables.value(43), $gameVariables.value(44), $gameVariables.value(45))

Spoiler: Total
Code:
$gameVariables.value(41) + $gameVariables.value(42) + $gameVariables.value(43) + $gameVariables.value(44) + $gameVariables.value(45) - $gameVariables.value(46)
Just FYI, his/her name is Andar, not Ander for when you tagged him/her.
Sorry I just realised that mistake. It automatically filled in the name so I thought it was correct.

The reason for the mistake was I wrongly thought RPG Maker MV was still in ruby so my searches for help were likely wrong. I had implemented the math.min function but not in the correct way as you showed. I was trying to subtract the lowest die from the total yes, thank you very much. I will run this to see if it helps. Yes it worked perfectly, thank you so much.

Original thread: https://forums.rpgmakerweb.com/threads/need-help-adding-variables-checking-minimum.90086/