msgbox with random number

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 🙂
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);

Original thread: https://forums.rpgmakerweb.com/threads/msgbox-with-random-number.74152/