MV Conditional if statement causing maximum call size error (Passive state conditions)

Not really sure what is going on here, I am pretty sure the script call is accurate.

Code:
<Custom Passive Condition>
if ($gameActors.actor(37).equips()[1].atypeId === 7) {
     value = true;
   } else {
     value = false;
   }
  </Custom Passive Condition>

Inputting $gameActors.actor(37).equips()[1].atypeId === 7 in console returns true. Setting the same code in a script call that is activated by talking to an NPC has also been confirmed to work, returning a specified set variable if the item is equipped or not. I am pretty sure my Custom Passive Conditions plugin is working fine as well, as the following code works exactly as intended:

Code:
Custom Passive Condition>
  if (
user.actorId() === 37) {
    condition = true;

  } else {
    condition = false;
  }
  </Custom Passive Condition>

This should be easy enough, but I am having zero luck figuring out why the first piece of code is returning Maximum Call Size Stack exceeded whenever it is run through the Custom Passive Conditions tag.

Any ideas what I am messing up?
how and where are you scanning for that tag?
Yanfly custom passive states activates the state from an equipped piece of armor, and this is the tag inside the passive state to determine if it should work or not.

Switching it to the below got it working, but I am still kind of curious, why was the above code throwing errors when called?

Actually it turns out this code doesn't work either, it just doesn't cause an error like the first and defaults the passive condition to true for some reason, regardless of what is equipped.

Code:
<Custom Passive Condition>
  if (
user.equips()[1].atypeId === 7) {
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>
eyeballing it here, but I think $actors.actor might be triggering the main plugin to read the notebox and run whatever is in there, whereas user.equips() relies on itself (user) being already loaded.
That is the thing, even when the notebox had zero other code besides the custom passive condition, it was still causing 160+ errors to show in console before loading. I edited my earlier post, I was a bit hasty thinking I got this working. I have compared this code to other code I have that is working and I am perplexed why this isn't doing what it is supposed to.
the act of equipping the armor should return a true, by definition.
there should be no need to pull the actor in question to check IF it has the item equipped.

IDK how the plugin is coded, but if this block alone works when triggered outside of the plugin as you describe, and throws a stack error when used WITH the plugin, then that sounds like the plugin is doing the same thing twice.
I am actually equipping a crossbow with the passive state, which then is evaluated as true/false based on actor id + if a shield is equipped at the same time. I have the following code working without error, until I unequip the shield completely, which throws a null error (which allows the passive state to exist, conditions fulfilled or not).

I am just going to forsake trying to figure out why the original code didn't work, as all I really have to do now is insert a clause for the null statement somehow.

Thanks for working with me on this, I am usually alright at trial and erroring my way through JS, but when I end up not being able to understand even why an error occurred, it starts making me panic a bit. I think I could probably figure this last bit out, but I am definitely open for suggestions as to the best way to send a null result to the false conditional branch.

Code:
<Custom Passive Condition>
  if (
user.actorId() === 37 && user.equips()[1].atypeId === 7)
{
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>

<letbs>
sprite_name: Tristan
</letbs>


And got it, just had to add another conditional to see if anything was actually present in slot 1 in the first place. Intuitively, a null in a conditional should not allow the conditional to execute, but logically, it makes sense as the conditional is what serves as the guard that prevents said passive state from occurring. I never was much good at math 😅

Code:
<Custom Passive Condition>
  if (
user.actorId() === 37 && user.equips()[1] && user.equips()[1].atypeId === 7)
{
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>

<letbs>
sprite_name: Tristan_xbow_shield
</letbs>
a crossbow with the passive state, which then is evaluated as true/false based on actor id
yeah.... no.
that should be handled plugin side not item side.
preferably maybe actor side, but definitely not item side.

you shouldn't do any processing in the item, only provide data about itself that isn't available as part of the logical object.

I have a similar case with an attack formula, that only one actor has an exception for, and ran into a similar problem.
I don't remember getting a stack error, but I wasn't able to pull the actor from the item, to then pull the item again from the actor, so I reversed the calculation and put it in the actor.
I could definitely use something else to call the passive, and add an additional && conditional to make sure crossbow type weapon is equipped, but I am not sure what you mean exactly as to why this could cause an issue. The states I am applying are simply visual state tags to determine which sprite to display, so it seems the most logical to apply the states through the weapon itself I am trying to display, no?

For a second there I thought you were about to lecture me on how one shouldn't use a crossbow and a shield at the same time :LZSlol:

Thinking about it a bit more, actor provided passive state would be pretty clean I suppose. I just want to keep things interchangeable should I go ahead with a job class/sub-class style system. Hmmm... yea I suppose for now doing this on the actor would be a better fit, as I can only append a direct string to the tag which changes the sprites anyways.

Something else that came to mind, while it probably isn't needed, and the performance increase would be nil at best, it would be a lot cleaner and more professional to run a conditional in the actor's notebox first in order to provide a state, rather than activating several passive states and only letting the the ones whose conditions match be activated after the fact. Probably wouldn't be too difficult to amend the code this way in fact. But... I do have it working currently without any issues, so maybe I should just be happy with that and try not to stir the pot too much.

Final code, with the passive state added through the actor notebox:


Code:
<Custom Passive Condition>
  if (
user.actorId() === 37 && user.equips()[0] && user.equips()[0].wtypeId === 21 && user.equips()[1] && user.equips()[1].atypeId === 7)
{
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>
<letbs>
sprite_name: Tristan_xbow_shield
</letbs>
it seems the most logical to apply the states through the weapon itself
yes, but that processing must be done by the plugin, not the item itself.
if you must provide both the actor and the alternate values because there are multiple options to choose from, use a hash.

Code:
{weapon1 => spriteA,
weapon2 => spriteB,
weapon3 => spriteC}

other actors may have weapon1 => spriteD, or another combination.

when using note tags, use them to provide data, not do processing.
How would I go about doing that? I was of the impression that it wasn't possible to input anything other than a direct string inside the <LeTBS> tags, and that it also was not possible to have notetags only execute upon conditionals, aside from the workaround I was doing using the activation/inhibition of passive states. I would absolutely love being able to store an actor name in a variable, and call that variable to determine which sprite to use, but I just thought that wasn't something you could do really. It would save me likely hundreds of states that serve no purpose other than determining which skin to use.


1651464556912.png
I don't know... I'm not familiar with the system.

note tags are simple text.
it its the core plugin that decides how to use them... but if there's a relationship between objects being loaded to access those note tags, you can end up in a loop where an item would call an actor and it be checked for equipment, and that would call the actor again, and so on.

the way to avoid that is to remove any instructions from the note tags, and leave only plain data.
and from there, if you need a conditioned output, the most adequate solution is a hash, because a hash *returns* an output *upon* reception of data... no code, no check, no nothing.
one piece of data for the equation is the actor holding the hash itself and providing it as input, and the other is the item being used.
all of that is core functionality of the hash object, outside any plugins.
I understand, and can see that issues could arise in a loop leading to slowdown and even crashes. Not exactly sure where to start with using hashes, but it sounds like something I could benefit from learning about a bit. Much appreciation for the information and guidance.
This code shouldn't throw you any errors. I just tested it in a game, nothing.

Have you checked that your Yanfly plugins are all the latest version and they're in your plugin manager in the order listed on the Yanfly Plugin Library Web site? Either of those things being off can cause weird errors.
Thanks ATT, I will do some debugging and see what could have caused the issue. I think gstv87 may have been onto something, with the call being cycled through causing the overflow error. It still doesn't explain fully why changing the code to user.equips ended up working really, but possibly due to the differences in how the check was called. Very odd behavior, I was beginning to think I was losing my mind for a bit there, or that JS had another surprise for me in regards to properly formatting my code. Happy to see that isn't the case.
I think gstv87 may have been onto something, with the call being cycled through causing the overflow error.
I don't see how. "calling an actor" to reference information doesn't trigger anything on passive state conditions. Of course, I don't see that you posted your actual errors anyplace to look at, but like I said, I put your original code into my game and it works exactly as expected.

That's why I recommended you troubleshoot your actual plugin installation, there's no reason this shouldn't work.
It still doesn't explain fully why changing the code to user.equips ended up working
It does? You said earlier:
Actually it turns out this code doesn't work either, it just doesn't cause an error like the first and defaults the passive condition to true for some reason, regardless of what is equipped.

Regardless, when you say
even when the notebox had zero other code besides the custom passive condition, it was still causing 160+ errors to show in console before loading.
that's telling me the plugin isn't working right.

And just as a tip, this isn't done correctly:
I have the following code working without error, until I unequip the shield completely, which throws a null error (which allows the passive state to exist, conditions fulfilled or not).

Code:
<Custom Passive Condition>
  if (
user.actorId() === 37 && user.equips()[1].atypeId === 7)
{
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>
The null error is not coming from the user ID not being 37, it's coming from the user not having anything in equips slot 1.

It would correctly be:
Code:
condition=user.actorId()==37 && user.equips()[1] && user.equips()[1].atypeId==7;

Just out of curiosity, if all of this only applies to actor 37, why isn't the passive state just on that actor? Get rid of the checks for the actor ID, save yourself some code.
I don't see how. "calling an actor" to reference information doesn't trigger anything on passive state conditions. Of course, I don't see that you posted your actual errors anyplace to look at, but like I said, I put your original code into my game and it works exactly as expected.

That's why I recommended you troubleshoot your actual plugin installation, there's no reason this shouldn't work.

It does? You said earlier:


Regardless, when you say

that's telling me the plugin isn't working right.

And just as a tip, this isn't done correctly:

The null error is not coming from the user ID not being 37, it's coming from the user not having anything in equips slot 1.

It would correctly be:
Code:
condition=user.actorId()==37 && user.equips()[1] && user.equips()[1].atypeId==7;

Just out of curiosity, if all of this only applies to actor 37, why isn't the passive state just on that actor? Get rid of the checks for the actor ID, save yourself some code.

Changing it to user.equips did work, the error I had was returning a null value when nothing was equipped in said slot. Putting an additional conditional to check if slot 1 was equipped before determining if slot 1 was equipped with aType 7 solved this.

Yes indeed, I did switch the state to be set by actor instead, and removed the user.actorId condition, instead using multiple conditionals to verify that both a crossbow and a shield are equipped at the same time. This does seem to be a better solution as the end script being run is specific for an actor anyways.

The code I ended up going with is this:

Code:
<Custom Passive Condition>
  if (
user.equips()[0] && user.equips()[0].wtypeId === 21 && user.equips()[1] && user.equips()[1].atypeId === 7)
{
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>

<letbs>
sprite_name: Tristan_xbow_shield
</letbs>

and

Code:
<Custom Passive Condition>
  if (
user.equips()[0] && user.equips()[0].wtypeId === 21 && !user.equips()[1])
{
    condition = true;
  } else {
    condition = false;
  }
  </Custom Passive Condition>

<letbs>
sprite_name: Tristan_xbow
</letbs>

Easy enough, besides the oddball error at the start. Some of my plugins may be out of date anyways, which could also explain the issue. I think for all purposes the working code I ended up using will do what I need for the various actors I have, and as a benefit of using an actor to determine sprite instead of an equipment piece, I can also reuse the code for enemy battlers (which are more or less just AI controlled versions of my actors).

Lots of work to make a system coming even close to Final Fantasy Tactics. Especially with the LeTBS plugin lacking the ability to use conditionals and variables in a lot of its notetag calls, or not being compatable with sprite graphic overlay scripts. For example, changing classes and providing a unique sprite for every weapon combination would total up to 120,000 sprite sheets and 12,000 different states determining which sprite sheet to use. Or having to use different versions of the same skills to determine attack range based on which weapon is equipped. Having a simple sprite overlay plugin that worked or ways to adjust LeTBS tags without cloning an entire skill type would save me so much trouble and open up so many possibilities. Instead I think I am going to have to settle with a subclass system that only provides additional skills, limiting the different possible combinations per character and class to 5-10 each, rather than 40-80 each. With about 150 characters and 40 different classes, it becomes obvious where I will run into limitations without going deep into the plugin code itself and rewriting things. Once again, I am shown how beneficial being well versed in JS is for MV.

Here is an example of the notetag for one skill, Lucky Strike, which is a dual wielding attack that factors luck into its damage formula. I can do a lot with the Yanfly plugins, but when it comes to LeTBS, I think I am stuck with using a direct sequence without making a duplicate skill.


damage formula = (a.atk + (Math.random() * a.luk)) * 3 - ((b.def + (Math.random() * b.luk)) * 4)
Code:
 <before eval>
var activeFighterID = BattleManagerTBS.activeEntity()._battler._actorId;
var value = activeFighterID;
$gameVariables.setValue(15, value);

$gameVariables.setValue(12, $gameActors.actor($gameVariables.value(15)).equips()[0].id);
$gameVariables.setValue(13, $gameActors.actor($gameVariables.value(15)).equips()[1].id);


$gameActors.actor($gameVariables.value(15)).changeEquip(1, $dataWeapons[0]);
 
</before eval>

<letbs>
scope: circle(1)
scope_select: enemies
sequence: lucky_strike
</letbs>

LeTBSConfig.js
"lucky_strike": [
"play_pose: user, atk",
"save_cells: lucky_strike_target, cursor_cell",
"effects: {aoe}_battlers, current_obj, obj_anim",
"wait: 20",
"use_skill: user, 36"
],

skill 36, Lucky Strike second swing:
(a.atk + (Math.random() * a.luk)) * 3 - ((b.def + (Math.random() * b.luk)) * 4)
Code:
<before eval>
$gameActors.actor($gameVariables.value(15)).changeEquip(0, $dataWeapons[$gameVariables.value(13)]);
  </before eval>

<after eval>
$gameActors.actor($gameVariables.value(15)).changeEquip(0, $dataWeapons[$gameVariables.value(12)]);
$gameActors.actor($gameVariables.value(15)).changeEquip(1, $dataWeapons[$gameVariables.value(13)]);
</after eval>

Unless there is some way to contain the <letbs> tags inside a conditional if statement, I will have to duplicate both skills and the sequence for every weapon with a different range (such as a spear, or firearm), whose range is set by scope: circle(1). This is much the same as the issue with the sprite_name: Tristan notetag inside the <letbs> tag inside the states I am using to determine which sprite to use.

A bit of runaround to do something that could be handled inside a single conditional statement, but I can't exactly put JS inside the LeTBS notetags I don't think, nor have multiple LeTBS notetags inside the same skill or state and only run on a conditional, not without some deep edits to the core LeTBS system. As far as I am aware, anyways..

Original thread: https://forums.rpgmakerweb.com/threads/conditional-if-statement-causing-maximum-call-size-error-passive-state-conditions.147240/