Convert arguments from plugin commands

Status
Not open for further replies.

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,710
Reaction score
1,127
First Language
Portuguese - Br
Primarily Uses
RMMZ
Hi there people!
Well, I have a plugin with a lot of plugin commands.
It happens that some arguments are Number, boolean or strings(default ones).
I was converting each argument in each command the type that he has to be.

JavaScript:
Eli.SuperTimer.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
Eli.SuperTimer.Game_Interpreter_pluginCommand.call(this, command, args);
let commandUpper = command.toUpperCase();
let nArg0 = parseInt(args[0]); // number
let nArg1 = parseInt(args[1]); // number
let pArgs = JSON.parse(args[2]); // boolean
// code here...
}
So I want to know a method to JSON.parse all the args because if I manage to do that, I will don't need to constantly convert them.
I have been trying some things, but I can't see in the console the results, to check how it's going.
Only thing I know that in-game they not work.
So I tried this:

JavaScript:
Eli.SuperTimer.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function (command, args) {
Eli.SuperTimer.Game_Interpreter_pluginCommand.call(this, command, args);
let commandUpper = command.toUpperCase();
let pArgs = JSON.parse(args); // This will work?
// commands and code here...
My intention is, with this, now use in the code:
TIMER_START 10 TRUE OK
Command = TIMER_START.
10 = pArg[0] // number
true = pArg[1] // boolean
OK = pArg[2] // string

So the Mv will convert each argument to the proper type he is(Number, boolean...)
I know that each argument inserted is like a .push in an array of arguments.
But this array is always empty, right? They only get a fill after I type each argument in the plugin command. Right?

[EDIT]
This have worked:
JavaScript:
for(let i = 5, l = args.length; l < i; i--){
    args.push("0")
}
let pArgs0 = JSON.parse(args[0]);
let pArgs1 = JSON.parse(args[1]);
let pArgs2 = JSON.parse(args[2]);
let pArgs3 = JSON.parse(args[3]);
let pArgs4 = JSON.parse(args[4]);
Now I use pArgs0 in the code and work.
But maybe there is another way?

[[EDIT 2]]
hahaha guess I'm too tired to code now xD
Can forget about this thread xD
 
Last edited:

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,729
Reaction score
4,685
First Language
English
Primarily Uses
RMMZ

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,049
Messages
1,018,547
Members
137,835
Latest member
yetisteven
Top