msgbox with random number

Nicke

Fortune seeker
Veteran
Joined
Apr 4, 2012
Messages
550
Reaction score
552
First Language
Swedish
Primarily Uses
RMMZ
I am not exactly sure but my guess would be that since we are doing math equations it will automatically convert it to an integer. Since $gameMessage.add needs a string it will throw a undefined error unless you convert the integer to a string like I did in my example.


As for your next question of adding text you can simple do like this:


var i = Math.floor(Math.random()*(104-18+1)+18);
$gameMessage.add("More text before. " + i +
". More text after.");


Lastly with variables you need to convert it to a string since they are integers from start. Like this:


var j = "Variable value";
$gameVariables.setValue(144, j);




You will see here that we don't need the "String()" because we use the "" quotes instead. Hope that helps :)
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,004
First Language
Tagalog
Primarily Uses
RMVXA
Only qustion left, if I want to add value to variabl 144, how I do? Already try the  $gameVariables.setValue(var, value);  and it's did'T work.

What did you try?


If you want to add "value" to the current value of variable 144, you might wanna do this


$gameVariables.setValue(144, $gameVariables.value(144)+value);


or


var x = $gameVariables.value(144)+value;


$gameVariables.setValue(144, x);
 

Latest Threads

Latest Posts

Latest Profile Posts

Not sure if it's true (and I won't judge or blame anyone if it is, really), but I heard from confident sources that you guys (and girls) really really like to
How is this new year for everyone? Hope you are well. Still deep in Covid in the US. Its like a vampire and refuses to die with even more strains. I need some holy water to kill it with.
in my game, what's known as HeadSpace is combining with the real world...
oh looks like the forums updated while I wasn't looking and we can put a banner now. Neat!
Treating this as a devlog

Forum statistics

Threads
107,663
Messages
1,031,239
Members
139,788
Latest member
coyoteandghost
Top