Can anyone see what is wrong with this script?

I have been tweaking this script and experimenting with pieces of it in smaller events to make sure I am doing everything correctly. Unfortunately, I am at a spot where it seems something is wrong and I can't figure out what. I have double checked what I think are the appropriate spaces.


if ($gameVariables.value(410) >= $gameVariables.value(411) &&

$gameVariables.value(410) >= $gameVariables.value(412) &&

$gameVariables.value(410) >= $gameVariables.value(413) &&

$gameVariables.value(410) >= $gameVariables.value(414) &&

$gameVariables.value(410) >= $gameVariables.value(415) &&

$gameVariables.value(410) >= $gameVariables.value(362) &&

$gameVariables.value(410) >= $gameVariables.value(363) &&

$gameVariables.value(410) >= $gameVariables.value(364) &&

$gameVariables.value(410) >= $gameVariables.value(365) &&

$gameVariables.value(410) >= $gameVariables.value(366) &&

$gameVariables.value(410) >= $gameVariables.value(367)) {

$gameVariables.value(400).push("A1");

$gameVariables.value(410) = 0;

$gameVariables.setValue(398, $gameVariables.value(398) -1);

this.command119(["Skip"]);

}

I have a single space after every "&&".
Are there supposed to be spaces after the "{" and after each" ;"?

I tested the concept of having multiple && and it worked fine. I tested the push script and the subtracting script. I also tested the Jump to Label script.

But I am still getting this error message. I just can't see the error.

Reference Error.png

Thanks to anyone who can spot what I am doing wrong!
Are you just wanting to check if one variable is greater or equal to all of those others?

I admittedly haven't worked with the editor variables much, and I might not be properly understanding your goal, but I think this might be an easier way of doing it:

JavaScript:
const v = 1; // id of your main variable
const variables = [2, 3, 4]; // ids of every other variable to check against
if (!variables.some(variable => { return $gameVariables.value(variable) > $gameVariables.value(v) })) {
    // do something if v is > than everything in variables
    console.log('v is greater');
} else {
    // do something if any value in variables is > than v
    console.log('a variable in variables is greater than v');
}

There are some syntax wizards on the forums here who can likely give you an even better answer.
Is this in a plugin or a script call? If it's a plugin, hit F8 and post the console output which will show what line triggered the error.

Also, did you type all of the above manually, or did you copy/paste from your editor? If you typed it, copy/paste from your editor, as you may have a typo in there that you didn't make when you entered it manually in your post.

$gameVariables.value(400).push("A1");

$gameVariables.value(410) = 0;

This isn't right.

$gameVariables.setValue(400, "A1");
$gameVariables.setValue(410, 0);

If var 400 is meant to be an array, try
var arr = $gameVariables.value(400);
arr.push("A1");
$gameVariables.setValue(400, arr);

There's also a method to access the variable data directly so you don't have to go through the .setValue command.

edit: but I see you've already asked for help with the variables/array thing in another thread, so if THAT is the command that isn't working, probably best to go back there for further assistance with the syntax.
Thanks @Kenen and @Shaz !

I should have provided context. I had created an Event for experimenting with establishing Turn Order for combat. I successfully made the Event using nested Conditional Branches. It works fine.

So I am trying to make that Event more efficient by experimenting with different ways to make it. It is not a plugin.

I originally typed a shortened version of most of the Script into an Event to test things. Then I copied and pasted parts of the Script to save time. I copied the final Script directly from my Event and posted it here.

What the Event is doing is checking to see if the initiative of an actor or enemy is equal to or greater than all the rest of the actors and enemies. If so, it adds the identifier of that actor or enemy to a Turn Order Array. I gave 6 actors and 6 enemies initiative values for testing purposes.

I set a variable for the number of actors and enemies in the combat and I then loop through the checks that many times. In the Event, the actor or enemy ID with the highest initiative value is pushed to the Array, the initiative of that actor or enemy is set to 0 so it won't be added again, the variable tracking the number of actors/enemies in combat is reduced by 1, and then the Event Jumps to a Label to check to see if the variable that tracks the number of actors/enemies has reached 0. If so, it Breaks the Loop. If not, it loops again to add another actor/enemy to the Turn Order Array based on the next highest initiative value.

If more than one actor/enemy has an equal initiative, the one that is checked first will be the one added to the Turn Order Array first.

I was trying to recreate that Event by getting rid of the nested conditional branches and using scripts because it is shorter.

I see the mistakes now in adding the actor/enemy ID to the array and changing the tracking variable. Thanks for that!

This was the Event that I originally thought I might be able to make by using Objects in an Array. But from another post tonight, you might have seen that my foray into using Objects was bumpy.

I will try making the changes that were noted above to see if that fixes the problem. I will also try retyping the entire script from scratch to see if that helps.

Although I am still not entirely clear on where spaces need to go around the { } part.

I am also interested in anything that makes this more efficient. Again, I am experimenting with figuring out how to Event a Turn Order for a Battle System.

Again, thanks for the responses and suggestions. I will give them a try first thing in the morning!
Thanks @Kenen and @Shaz !

I should have provided context. I had created an Event for experimenting with establishing Turn Order for combat. I successfully made the Event using nested Conditional Branches. It works fine.

So I am trying to make that Event more efficient by experimenting with different ways to make it. It is not a plugin.

I originally typed a shortened version of most of the Script into an Event to test things. Then I copied and pasted parts of the Script to save time. I copied the final Script directly from my Event and posted it here.

What the Event is doing is checking to see if the initiative of an actor or enemy is equal to or greater than all the rest of the actors and enemies. If so, it adds the identifier of that actor or enemy to a Turn Order Array. I gave 6 actors and 6 enemies initiative values for testing purposes.

I set a variable for the number of actors and enemies in the combat and I then loop through the checks that many times. In the Event, the actor or enemy ID with the highest initiative value is pushed to the Array, the initiative of that actor or enemy is set to 0 so it won't be added again, the variable tracking the number of actors/enemies in combat is reduced by 1, and then the Event Jumps to a Label to check to see if the variable that tracks the number of actors/enemies has reached 0. If so, it Breaks the Loop. If not, it loops again to add another actor/enemy to the Turn Order Array based on the next highest initiative value.

If more than one actor/enemy has an equal initiative, the one that is checked first will be the one added to the Turn Order Array first.

I was trying to recreate that Event by getting rid of the nested conditional branches and using scripts because it is shorter.

I see the mistakes now in adding the actor/enemy ID to the array and changing the tracking variable. Thanks for that!

This was the Event that I originally thought I might be able to make by using Objects in an Array. But from another post tonight, you might have seen that my foray into using Objects was bumpy.

I will try making the changes that were noted above to see if that fixes the problem. I will also try retyping the entire script from scratch to see if that helps.

Although I am still not entirely clear on where spaces need to go around the { } part.

I am also interested in anything that makes this more efficient. Again, I am experimenting with figuring out how to Event a Turn Order for a Battle System.

Again, thanks for the responses and suggestions. I will give them a try first thing in the morning!
Rather than looping through every battler and then comparing them against every battler, why not just take the array of battlers, sort them by initiative value, and then map them into an array of battler IDs?
Rather than looping through every battler and then comparing them against every battler, why not just take the array of battlers, sort them by initiative value, and then map them into an array of battler IDs?
I was actually trying to figure out how to do that and I was thinking I would need to use an Array with Objects. Which went down a rabbit hole to dark and scary places.

I'm not sure how to sort an array that has separate values for battlers ID and then their initiatives.

I thought that would actually be the simplest way, but I couldn't figure out how to do it.
I was actually trying to figure out how to do that and I was thinking I would need to use an Array with Objects. Which went down a rabbit hole to dark and scary places.

I'm not sure how to sort an array that has separate values for battlers ID and then their initiatives.

I thought that would actually be the simplest way, but I couldn't figure out how to do it.
The Array class has a .map() function that iterates through each element, runs a function on it, and then returns a new array where each element is the result of running the function on the element. So for example:

$gameParty.members().map(member => member.agi)

Will give you an array of each party member's agility.
The Array class has a .map() function that iterates through each element, runs a function on it, and then returns a new array where each element is the result of running the function on the element. So for example:

$gameParty.members().map(member => member.agi)

Will give you an array of each party member's agility.
Ah, thanks for that! I will experiment with that. Although the reason I am exploring all of this is because I think I want more attributes than default MZ will allow. So I am trying to learn how to track and do things separately. I have so much to learn!

@Shaz Your two suggestions worked like a charm. Here is the altered script that is repeated throughout the Event:

if ($gameVariables.value(367) >= $gameVariables.value(410) &&
$gameVariables.value(367) >= $gameVariables.value(411) &&
$gameVariables.value(367) >= $gameVariables.value(412) &&
$gameVariables.value(367) >= $gameVariables.value(413) &&
$gameVariables.value(367) >= $gameVariables.value(414) &&
$gameVariables.value(367) >= $gameVariables.value(415) &&
$gameVariables.value(367) >= $gameVariables.value(362) &&
$gameVariables.value(367) >= $gameVariables.value(363) &&
$gameVariables.value(367) >= $gameVariables.value(364) &&
$gameVariables.value(367) >= $gameVariables.value(365) &&
$gameVariables.value(367) >= $gameVariables.value(366)) {
var arr = $gameVariables.value(400);
arr.push("E6");
$gameVariables.setValue(400, arr);
$gameVariables.setValue(367, 0);
$gameVariables.setValue(398, $gameVariables.value(398) -1);
this.command119(["Skip"]);
}

I will continue to experiment with alternate ways to do this, but right now, I have at least two that seem to work. They probably aren't pretty, but they work.

Thanks for the assistance and helping me learn some new stuff!

Tomorrow is a new day!
@Shaz Hi! I could have misunderstood your previous response, but I got the impression that something like this in a Script isn't supposed to work where 400 is a blank array that was previously created:


$gameVariables.value(400).push("Actor 1");

$gameVariables.value(400).push("Actor 2");

However, I went back to see why I thought this would work and here is the event that I created and it actually works. It pushes the values of Actor 1, Actor 2, and Actor 3 to the array and the last \V[400] displays them all.

Am I missing something where this isn't supposed to work?

Script Push to Array.png
I might have just misunderstood what you were pointing out, but I just wanted to double check.

Thanks!
It works. Shaz was encouraging you to use slightly more correct syntax with the included setter method, but I don't think she meant to tell you it couldn't work.

The second line quoted in that post - $gameVariables.value(410) = 0; - is both not right and can't work.
It works. Shaz was encouraging you to use slightly more correct syntax with the included setter method, but I don't think she meant to tell you it couldn't work.

The second line quoted in that post - $gameVariables.value(410) = 0; - is both not right and can't work.
Thanks for clarifying! I could understand why the second part was wrong after I saw it. I had fixed it in one stop but not the other.

I was just confused about the first part and it is good to know that it is better to do it the other way.

Thanks again!

EDIT: And I just noticed that I double posted a bit earlier in this thread. Sorry about that.

Original thread: https://forums.rpgmakerweb.com/threads/can-anyone-see-what-is-wrong-with-this-script.154310/