MV How is the correct syntax to get all 3 argunemts ["add", "weapon", "3"] in separat js.variables ?

This Script Call list applies to both RPG Maker MV and RPG Maker MZ.
Link here to see the entire list.



Supplementary Material for RPG Maker MZ:

Have fun eventing~



Hi,

in this excel_sheet at sheet 'Advanced' the first entry
[TABLE]
[TR]
[TD]Plugin Command
[MV][/TD]
[TD]interpreter.pluginCommand(command, args);[/TD]
[TD]// In a Script command: invoke plugin command ItemBook add weapon 3
this.pluginCommand("ItemBook", ["add", "weapon", "3"]);[/TD]
[TD]interpreter = a Game_Interpreter reference
command = command name
args = array of arguments

All arguments are passed in JSON/stringified format.[/TD]
[/TR]
[/TABLE]

How is the correct syntax to get all 3 argunemts ["add", "weapon", "3"] in separat js.variables ?


With kindest regards
and Thank you in advance
Nafraju
How is the correct syntax to get all 3 argunemts ["add", "weapon", "3"] in separat js.variables ?
The same way you use variables otherwise 😉
Code:
var arg1="add", arg2="weapon", arg3="3";
this.pluginCommand("ItemBook", [arg1, arg2, arg3]);
The same way you use variables otherwise 😉
Code:
var arg1="add", arg2="weapon", arg3="3";
this.pluginCommand("ItemBook", [arg1, arg2, arg3]);

Hi @ATT_Turan ,

the other way round, to get them out of this array into separate variables ?
Hi @ATT_Turan ,

the other way round, to get them out of this array into separate variables ?
I'm sorry, I'm really not sure what you're asking. They are separate variables, I defined them one at a time in the first line of my code.

The array only exists for the purpose of the pluginCommand method. You can see how it uses arguments inside of that function in the code - if you have a question about editing that and you're not sure how to achieve what you want, you should start a new thread with details.
I'm sorry, I'm really not sure what you're asking. They are separate variables, I defined them one at a time in the first line of my code.

The array only exists for the purpose of the pluginCommand method. You can see how it uses arguments inside of that function in the code - if you have a question about editing that and you're not sure how to achieve what you want, you should start a new thread with details.


this.pluginCommand("ItemBook", [arg1, arg2, arg3]);

var MyVariable_1 = ?arg1?;
var MyVariable_2 = ?arg2?;
var MyVariable_3 = ?arg3?;

in php you do this with the name of the array and the index
i.e.
MyVariable_1 = $NameOfArray[0];
MyVariable_2 = $NameOfArray[1];
MyVariable_3 = $NameOfArray[2];

How is this here to do ?
this.pluginCommand("ItemBook", [arg1, arg2, arg3]);

var MyVariable_1 = ?arg1?;
var MyVariable_2 = ?arg2?;
var MyVariable_3 = ?arg3?;

in php you do this with the name of the array and the index
i.e.
MyVariable_1 = $NameOfArray[0];
MyVariable_2 = $NameOfArray[1];
MyVariable_3 = $NameOfArray[2];

How is this here to do ?
It's basically the same. You can see if you just open the JS file and look at the code of the pluginCommand function. Here's also a reference for you:

It's basically the same. You can see if you just open the JS file and look at the code of the pluginCommand function. Here's also a reference for you:


Readed and last Question:

the name of the array here is args
so

var MyValiable_01 = args[0]; // of this array ["add", "weapon", "3"] set "add"

Is that right ?
Since this doesn't seem to be specific to the Script Call List...

I've split this into its own thread in Learning JavaScript. Thank you.


Like ATT_Turan said, the array in the example you quoted is anonymous. If you name it then you can access it, e.g.
JavaScript:
const args = ["add", "weapon", "3"];
console.log(args[0]);  // > "add"
Otherwise you can only access the values from within the method, after it has been received as a function argument. Here's the method from the RMMV core scripts (rpg_objects.js):
JavaScript:
Game_Interpreter.prototype.pluginCommand = function(command, args) {
    // to be overridden by plugins
};
As you can see, the second argument is named args here. So, within that function, you can reference the value of the second argument passed into the function as args.

Original thread: https://forums.rpgmakerweb.com/threads/how-is-the-correct-syntax-to-get-all-3-argunemts-add-weapon-3-in-separat-js-variables.147257/