MZ How can I make constants and functions globally accessible within plugin commands and script calls.

I am working on making a DnD style RPG game, complete with all 6 ability scores.
However the 6 ability scores don't really match up to RPG Maker's parameters, so I will need to change the behavior of various formulas, as each ability score is mapped to a different parameter in RPG Maker.

However, when planning it out, its not the most readable, for example a roll using charisma would be
Code:
(Math.floor((user.luk-10)/2)+Math.floor(Math.random(20))+1)

instead I like to be more readable to something like, using some global constants and functions

Code:
modifier(user.parms(CHARISMA)) + roll(20)


where
CHARISMA is a global constant that would make user.params() map to the user.luc parameter.
and modifer() and roll() are global functions.

Is there a way to do this?
Create a new JS file.
Write window["CHARISMA"] = 34
Add as a plugin.
Horray, you made a new global constant!
Your original code is not quite correct. Math.random() does not take any argument - it generates a random value between 0 and .99 barred.

You might be confusing it with RPG Maker's Math.randomInt(), which does take an argument and generates a random integer between 0 and n-1. But, in that case, there's no need to use Math.floor() again.

I would also caution against using unnecessary parentheses, as it's a good way to get confused 😉

For example, Math.floor((user.luk-10)/2)+Math.randomInt(20)+1

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-make-constants-and-functions-globally-accessible-within-plugin-commands-and-script-calls.151090/