Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
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]
 

Attachments

  • error.png
    error.png
    7.9 KB · Views: 10

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,125
Reaction score
8,002
First Language
German
Primarily Uses
RMMV
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.
 

Rubescen

Veteran
Veteran
Joined
Jan 4, 2016
Messages
157
Reaction score
175
First Language
English
Primarily Uses
RMMZ
You could use something like this though:

script: $gameVariables.setValue(13, $gameVariables.value(9) + $gameVariables.value(10)) etc.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,235
Reaction score
14,259
First Language
English
Primarily Uses
RMMV
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]
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,125
Reaction score
8,002
First Language
German
Primarily Uses
RMMV
@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.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
41,235
Reaction score
14,259
First Language
English
Primarily Uses
RMMV
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.
 

Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
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))
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,125
Reaction score
8,002
First Language
German
Primarily Uses
RMMV
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).
 

Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
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?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,125
Reaction score
8,002
First Language
German
Primarily Uses
RMMV
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.
 

Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
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.
 
Last edited:

Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
@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.
 
Last edited:

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,123
First Language
English
Primarily Uses
RMMV
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:

ExampleRoll.png

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

Code:
$gameVariables.value(41) + $gameVariables.value(42) + $gameVariables.value(43) + $gameVariables.value(44) + $gameVariables.value(45) - $gameVariables.value(46)
 

Midnight Kitty

Midnight
Veteran
Joined
Jun 18, 2013
Messages
129
Reaction score
14
First Language
English
Primarily Uses
RMMV
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.
 

Latest Threads

Latest Profile Posts

I just lost an hour plus of time to trying to modify the _battlefield sprite... when in reality MZ calls it _battleField ;_;

Even when debugging for the "undefined value", it looked exactly the same to my 20/60 eyesight.

I really prefer this_naming_convention rather than thisNamingConvention !!
hmm... I just solved one of the more annoying sideview battler problems in MV.. Passive States and Visual States can make it so when your character is in crisis HP, they don't go back to normal walk/wait when it's their turn. they stay in the crisis motion... neat.
Apparently all of LGBT reddit hates me. I posted a simple question and only got hate mail. What's the deal? The doompost was literally 6 months ago and I've changed my views since then and apologized.
MOD NOTE: See second response before replying to this. - Wavelength
Amazing. Simply amazing...

JRPG Browser - Playlist:

Forum statistics

Threads
109,100
Messages
1,042,035
Members
141,585
Latest member
CiderV
Top