Help trying to read Arrays in Script Call

Hello, good evening, I have been trying to create a text command in "rpg_windows" that allows me to read Arrays within variables.

The idea of this was having to avoid putting all the Armor and Item numbers into a variable manually, since before I did the following: "$gameVariables.setValue(5, $gameParty.armors()]") and then it generated a text message with a scriptcall, because it could not directly call the icon of the object in question inside the text box with "\I[\V[5,1]]".

So inside the "rpg_windows" Plugin, in "convertEscapeCharacters", I added the following code:

JavaScript:
    text = text.replace(/\x1bW\[(\d+),(\d+)\]/gi, function() {
        return $gameVariables.value(parseInt(arguments[1]))[parseInt(arguments[2])].iconIndex;//MOD
   }.bind(this));

So when writing "\W[5,0]" it returns the array loaded in the Variable, it is worth clarifying that with this, I also attach the ".iconIndex" to the end of line 2, with that, I can use this command within the text window.

What is the problem? Since there is no established Array limit, if you write a number that is not loaded in the Player's inventory, you will get a "null" or "Undefined".

How could I avoid this?
How could I avoid this?
I suggest by taking a step back and explaining more clearly what you want to achieve with all of this.

If you're using code, there's no reason for you to be using any game variables in the first place since you could directly access the item database.

And there's no need for you to be writing this code yourself since there are already plugins that can parse JavaScript via message window escape codes.

So if you explain what the goal is, we can probably help you find a more efficient way.
Hello Turan! Sorry if I wasn't clear, what I was referring to this:
Designate to a Variable the amount of Armors that the Team carries in the Inventory. That is why I used $gameVariabes.setValue(5, $gameParty.armors()), once the Array was created, I added a slot to 5 variables, for example example:
"$gameVariabes.setValue(6, $gameVariabes.value(5)[0].iconIndex)."

So I could use the Text Code "\I[\V[6]]" to directly access the armor icon number stored in slot 0 without having to change it manually.

But I wanted to speed up the procedure, avoiding having to create many variables as I mentioned above, and take the number directly from Variable 5 and with any array.

That's why I wanted to make a text code that allows me to access a variable and any array it has inside.

The problem is that when calling a number that does not exist (obviously) there will be an error.

My idea was "If $gameVariables.value(5) <= "Saved Array"" It will make the icon appear, if not, nothing will be shown.

I don't know if you understood it, but that's basically what I've been trying to do.
Designate to a Variable the amount of Armors that the Team carries in the Inventory. That is why I used $gameVariabes.setValue(5, $gameParty.armors()), once the Array was created, I added a slot to 5 variables, for example example:
"$gameVariabes.setValue(6, $gameVariabes.value(5)[0].iconIndex)."
My point is that's an unnecessary extra step. $gameParty.armors() is already an array. So I don't see the point in adding it to a game variable. That doesn't do anything for you except take up one of your variables and make you type more stuff.

You can simply do
Code:
$gameVariables.setValue(6, $gameParty.armors()[0].iconIndex);

The problem is that when calling a number that does not exist (obviously) there will be an error.

My idea was "If $gameVariables.value(5) <= "Saved Array"" It will make the icon appear, if not, nothing will be shown.
This is the part I'm still confused about - how and why your game would be trying to reference an armor the party doesn't have. I guess maybe you're doing this inside a loop or something for some reason?

But you can simply put into the Script field of a Conditional Branch
Code:
$gameVariables.value(5) < $gameParty.armors().length
which will only return true if they have that many armors.

And at that point you can reference
Code:
$gameParty.armors()[$gameVariables.value(5)].iconIndex

Original thread: https://forums.rpgmakerweb.com/threads/help-trying-to-read-arrays-in-script-call.170338/