How do I generate a random whole number via scripting?
I tried using math.randomInt(100), math.random(100) and more. But it keeps telling me that math or random is not defined. But isn't that defined in javascript?
int(random(n))
If you want to use js, use the Browser object, or scripting, if you have that feature.
There's also the Advanced Random object if you need more advanced features, seed, noise, etc.
Develop games in your browser. Powerful, performant & highly capable.
Thank you for the reply. int(random(n)) gave me the same error that everything else that I tried did. That it is not defined.
I wrote this piece of script in the script.js file that is created inside the editor.
What am I doing wrong?
Maybe try leaving the int() off.
parseInt() perhaps.
I found what my issue was. When I learned javascript using the rpg maker I used things like math.randomInt(n). But as it seems that was just a function and not part of the original javascript language. Now I created my own function and it works.
Thanks for the help.
int and random are not built-in global functions in JavaScript. It looks like you're confusing Construct expressions with JS. In JS the correct code is Math.floor(Math.random() * 100) (for a random integer in the range 0-99 inclusive). See documentation on the Math object.
int
random
Math.floor(Math.random() * 100)