MZ Using Variables to store arrays in MZ

Having so many switches for each NPC and some being redundant and discovering the power of common events, I wanted to use arrays to move flags for each NPC character.

But, I'm having trouble using the syntax with script calls. I have zero Javascripting experience, but with Python I'm fair so program syntax is not lost on me. I referenced JavaScripts with examples, but this being inside an engine I might be doing something wrong.

I haven't gotten past the basic if $gameVariables.Value(1,[0]) == 0) then $gameSwitch.setValue(1, true)
I can set switches on and off, but cannot for the life of me get if then else statements to work, or if I'm doing the arrays correctly since technically like injecting text into variables using scripts, I'm sort of going outside the normal realm.

The initial string is:
JavaScript:
$gameVariables.setValue(1, [1, 0, 0, 0, 0])

Then basically try a basic if then as such.

JavaScript:
If ($gameVariables.Value(1, [0]) == 1) {
  $gameSwitches.setValue(1, true);
}

Then I just go with Condition in the menus for Switch 1, and it doesn't work.

The other function is a loop, is it wise to put it in script form during a common event call? And would $gameVariables(1.length) retrieve the length of the array.

What is the syntax when I want to let a variable define the index or even the $gameVariable/Switch ?

Thanks,
Jomei
JavaScript:
If ($gameVariables.Value(1, [0]) == 1)
This isn't proper syntax
It's $gameVariables.value(1)[0]
The value() method (not Value) returns the value of the variable, whether it's a single-element or an array.

So you can't try to do your array methods or manipulation as an argument you're passing into value(), you have to do it upon the returned value as AquaEcho demonstrated.

Code:
$gameVariables.value(x)[index]
$gameVariables.value(x).push(element)[code]

The only time you'd pass anything to do with arrays in as an argument is if you're using setValue().

[code]$gameVariables.setValue(x, []); // turns it into an array
$gameVariables.setValue(x, [1, 3, 4, 7]);
Something is wrong with my if statement as well and it's not syntax. I just used a script to define just a number. Found out about F9 saw that V1 = 1, but it still will not set the value to true in the script. When I just put the switch by itself it comes on. Is there something I'm missing?

JavaScript:
$gameVariables.setValue(1, 1);
if ($gameVariables.Value(1) == 1) {
  $gameSwitches.setValue(1, true);
}

Is there any way to check if I set up the array correctly?

So for length of the array on $gameVariables.value(1) Would be $gameVariables(1).length?
$gameVariables.value(1).length

You're still using Value and not value in your example; Javascript is case-sensitive. value and Value are two different functions, and only one of them exists in the default engine.
if ($gameVariables.Value(1) == 1) {
The Value should be lowercase
Well that was embarrassing, as I never would of caught that v. Insult to injury when I retyped I hit another #. I rely on an IDE too much.

AquaEcho thanks, I did not see that lowercase V in your statement, thanks.

Trihan I saw your other post. What is tripping me up it's having to deal with the $gameVariables.value(x) that makes it a bit of a learning curve on top of not being familiar with Java.

So after defining the array, how do you specify the value for the index and set the element when it changes?

If I didn't have to define x I would just:
Code:
let jomei = [ 'eat', 'game', 'sleep'];
jomei[1] = 'code';
//and I think to add to the array in java as ATT_Turan said
jomei.push('repeat')

It's having what I assume is an index on the game variable that perplexing me. Would it look like

# equals the gameVariable location
Index = y
element = z

$gameVariable.setValue(#,[y] z) = variable;
Well that was embarrassing, as I never would of caught that v. Insult to injury when I retyped I hit another #. I rely on an IDE too much.

AquaEcho thanks, I did not see that lowercase V in your statement, thanks.

Trihan I saw your other post. What is tripping me up it's having to deal with the $gameVariables.value(x) that makes it a bit of a learning curve on top of not being familiar with Java.

So after defining the array, how do you specify the value for the index and set the element when it changes?

If I didn't have to define x I would just:
Code:
let jomei = [ 'eat', 'game', 'sleep'];
jomei[1] = 'code';
//and I think to add to the array in java as ATT_Turan said
jomei.push('repeat')

It's having what I assume is an index on the game variable that perplexing me. Would it look like

# equals the gameVariable location
Index = y
element = z

$gameVariable.setValue(#,[y] z) = variable;
The best way to think of it is in terms of substitution.

You understand jomei[1], which is great.

Just replace "jomei" with "$gameVariables.value(x)"

$gameVariables.value(x)[1] is the same thing.

$gameVariables.value(x).push('repeat')
I also need to do mea culpa because I specifically told you when you would put anything inside the function call when using setValue() and then mistyped the examples.

(but I did also point out the lower case "V" 😉)
ATT_Turan, I missed it. I did not register the V on either post. My apologies for not catching that you also mentioned it, but it just flew over my head. I see it now that I know it was a capital issue.

Any suggestions for how to view created arrays for debugging when running RPG maker?
Any suggestions for how to view created arrays for debugging when running RPG maker?
Type the object that holds them into the developer console? I'm not sure where the confusion lies here; the only things that are there for debugging by default are the debug window and the console.
The method you can access within the editor is you do a Show Text command...one of the escape codes lets you display the value of a variable.
Just use SRD HUDMaker to display your variables on screen during playtest. That's what I do.

Original thread: https://forums.rpgmakerweb.com/threads/using-variables-to-store-arrays-in-mz.165333/