msgbox with random number

Discussion in 'Javascript/Plugin Support' started by XGuarden, Jan 27, 2017.

  1. Nicke

    Nicke Fortune seeker Veteran

    Messages:
    537
    Likes Received:
    523
    Location:
    Sweden
    First Language:
    Swedish
    Primarily Uses:
    RMMV
    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: Jan 29, 2017
    #21
  2. Engr. Adiktuzmiko

    Engr. Adiktuzmiko Chemical Engineer, Game Developer, Using BlinkBoy' Veteran

    Messages:
    14,640
    Likes Received:
    2,969
    Location:
    Philippines
    First Language:
    Tagalog
    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);
     
    #22

Share This Page