Lammaka

Villager
Member
Joined
Nov 21, 2022
Messages
5
Reaction score
0
First Language
Spanish
Primarily Uses
RMMV
Hello! I' m trying to multiply a variable by a number between x and y with a scrpt. Let's say x = 50 and y = 200. I tried with this one:


$gameParty.gainGold($gameVariables.value(52) * >= 50 && <= 200);

but is not working. Any ideas?
 

AquaEcho

Script Kitty
Regular
Joined
Sep 20, 2021
Messages
2,214
Reaction score
1,620
First Language
English
Primarily Uses
RMMV
Try this
$gameParty.gainGold($gameVariables.value(52) * (Math.floor(Math.random() * 151) + 50))
 

Lammaka

Villager
Member
Joined
Nov 21, 2022
Messages
5
Reaction score
0
First Language
Spanish
Primarily Uses
RMMV
It works! Thanks! However, as I have to repeat this process with other values, I would like to understand the math behind that formula. I mean, what should I do if I want to change the values? Why 151?
 

AquaEcho

Script Kitty
Regular
Joined
Sep 20, 2021
Messages
2,214
Reaction score
1,620
First Language
English
Primarily Uses
RMMV
Math.random() gives you a random decimal number between 0 inclusive and 1 exclusive or 0<=x<1.
(Math.random() * 151) gives you a random decimal number between 0 inclusive and 151 exclusive or 0<=x<151, so 0 to 150.
Math.floor will floor the result or round it down so it's an integer/whole number.
+50 will add 50 to the result and ensure a minimum value of 50.
So your result is a random integer/whole number between 50 and 200 inclusive.
 
Last edited:
  • Like
Reactions: Bex

Lammaka

Villager
Member
Joined
Nov 21, 2022
Messages
5
Reaction score
0
First Language
Spanish
Primarily Uses
RMMV
Ohh! I undestood! You're great. Thank you so much.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,465
Reaction score
10,841
First Language
English
Primarily Uses
RMMV
If it's easier, you can use the RPG Maker function Math.randomInt(X).

It will generate a number between 0 and X-1.

It's doing exactly the same thing behind the scenes as what @AquaEcho gave you, but it can be easier to read and work with.
 

Latest Profile Posts

I realized recently since my game is still a turn based game, that something like the card game Yomi is a lot closer to what I should try to aim for combat wise. Should also help for those who don't really play fighting games to make things a bit easier to understand. ugh the struggles of trying to show love for my 2 favorite genres in 1 go lol.
Did a bit of work on the chemistry tiles I want.

Hey There!


QPcure.png

My next plugin will be: "Dynamic Temperature Stats"

Now you might be wondering... What does it do?

Well, it's a fascinating plugin that adds a body temperature mechanic to characters.

(MORE INFO ⬇️)
Holy crap, it's cold. Our heat went out this morning and the repair guy won't get the part needed to fix it at least until tomorrow. Had to be now of all times, when we have stuff to do all week and it's the coldest night of November so far.
I have invented a new food: soupie!
It is soup-pie! It's what happens when you try to make a pie, and it turns out super gooey and falls apart and you need a spoon to eat it! Soupie! Said like sue-pie. Not soupy - oh just let me eat my sad apple pie :kaothx:

Forum statistics

Threads
136,561
Messages
1,267,579
Members
180,244
Latest member
buttermequeasy334
Top