• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Methods for rounding and random number

lx_theo

Game Developer
958
Posts
14
Years
    • Seen Nov 2, 2013
    [Answered] Methods for rounding and random number

    I want to do stuff that involve these two thing, or rounding numbers to the nearest whole number as well as picking a random number from a range of numbers. But I don't really know how to do these in the code used for the system. Any help in how to do these? Thanks to anyone who helps.
     
    Last edited:

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    Assuming you've got a float (which are uncommon in Essentials since most calculations of interest are automatically rounded down to an integer after every calculation), then you can use num.round.

    5+rand(10) will give you a random integer between 5 and 14 inclusive (rand generates a random integer between 0 and 1 less than the number, inclusive).

    If you have a selection of numbers in an array, such as array=[1,3,5,7,9], then use array[rand(array.length)] to pick a random number from it.

    A quick Google search would have told you all this.
     

    lx_theo

    Game Developer
    958
    Posts
    14
    Years
    • Seen Nov 2, 2013
    I find myself being almost completely incompetent at google when it comes to programming related subjects, so thank you.
     

    Luka S.J.

    Jealous Croatian
    1,270
    Posts
    15
    Years
  • You don't really need Google for things like that. People forget that RMXP is actually quite neat, and comes with some nice documentation. If you press F1 while in the script editor, just search for things like "random number" or "rounding", and you can simply find what you are looking for. All of the built-in functions can be found there, and usually, there are good explanations on what they do and how to use them.
     
    Back
    Top