How to set a variable to 1 ? \V[x] - (rand($game_variables[x] +1

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
675
Reaction score
78
First Language
English
Primarily Uses
In VX Ace the way I did this was set the Operand to Script: rand($game_variables[1] +1

Does anyone know how to rewrite this script for MV?  I'm getting a syntax error.
 

Schlangan

A madman with a computer
Veteran
Joined
May 20, 2015
Messages
1,446
Reaction score
1,738
First Language
French
Primarily Uses
RMMV
Do you want a random number based on a value in a variable ? This should do the trick :

Code:
Math.random($gameVariables.value(1)+1);
Edit : I don't know what the rand(X) function of VXAce did, but if it was giving a value between 0 and X, you should do:

Code:
Math.random()*($gameVariables.value(1)+1);
And if you want integers only :

Code:
Math.floor(Math.random()*($gameVariables.value(1)+1));
 
Last edited by a moderator:

Berylstone

Veteran
Veteran
Joined
Jun 3, 2013
Messages
675
Reaction score
78
First Language
English
Primarily Uses
Do you want a random number based on a value in a variable ? This should do the trick :

Math.random($gameVariables.value(1)+1);Edit : I don't know what the rand(X) function of VXAce did, but if it was giving a value between 0 and X, you should do:

Code:
Math.random()*($gameVariables.value(1)+1);
And if you want integers only :

Code:
Math.floor(Math.random()*($gameVariables.value(1)+1));
Thank you Schlangan.

What I was wanting to do was set up a random number between 1 and a variable.  The default random operand doesn't allow me to use variables - just straight numbers like 1 ? 2.  I was wanting to set a variable to random: 1 ? \V[x].  So it was giving me some problems.

Math.random()*($gameVariables.value(1)+1); looks to be working for what I wanted to do.  I do appreciate the help.
 
Last edited by a moderator:

Latest Threads

Latest Profile Posts

Only 3 more days to get your copy of Move That Box! with -15% discount!
1660090657213.png
Mistakes will be made.
After three years, it was awesome to be back at Gen Con!
Words of Wisdom: You can be honest and alone. Or dishonest and together.
Working on mapping using RPGTools to create parallax maps using PVgames tiles/assets. It's super cool... but mapping is still something I drag my feet on getting done. I hate this but love the math parts of design, which is the opposite of a lot of dev's around, I think. It really do be different strokes for different folks.

Forum statistics

Threads
124,381
Messages
1,163,230
Members
163,180
Latest member
Viking
Top