Script to check if any pt member has a state

I know ($gameActors.actor(x).isStateAffected(x)) works for a single actor, but how do I check if it's any party member?
$gameActors.members().filter {|actor| actor.isStateAffected(x)}.length > 0


It won't tell you who is affected, just that one or more party members are.
$gameActors.members().filter {|actor| actor.isStateAffected(x)}.length > 0


It won't tell you who is affected, just that one or more party members are.

Wow that was fast! Well I put it in and got this: SyntaxError Unexpected {


This is what I've got:


<Custom Show Eval>


if ($gameActors.members().filter {|actor| actor.isStateAffected(x)}.length > 0) {


visible = true;


} else {


visible = false;


}


</Custom Show Eval>


So I'm guessing it was the { before |actor|. Some background: I'm using this in the note box of a skill to check if any party member has a certain state and if someone does then this skill will become visible for use. Yanfly's Skill Core plugin uses this.
does it give the position of the { character or the line?  It could be the one at the end of the line.


Oh - change it to $gameParty.members() rather than $gameActors.members() - not sure if that's the problem (I'd expect a different error message).
does it give the position of the { character or the line?  It could be the one at the end of the line.


Oh - change it to $gameParty.members() rather than $gameActors.members() - not sure if that's the problem (I'd expect a different error message).

Same error, it's this http://prnt.sc/ccq0yk
If you open the console, does it give you any more information?  Can you copy/paste the console output?
If you open the console, does it give you any more information?  Can you copy/paste the console output?

SyntaxError: Unexpected token { at Game_Actor.Game_BattlerBase.meetsCustomShowEval


Does this help?
Is that everything in the console?  I'd expect a script name, a script line, and maybe a character position.


I'm guessing that function comes from Yanfly's script.  I don't know what it expects/accepts.  I think the syntax is correct, and it should work if you were running it in a regular script or script call.  So I suspect it's something with the plugin's requirements.
Is that everything in the console?  I'd expect a script name, a script line, and maybe a character position.


I'm guessing that function comes from Yanfly's script.  I don't know what it expects/accepts.  I think the syntax is correct, and it should work if you were running it in a regular script or script call.  So I suspect it's something with the plugin's requirements.

Does this being during a battle make any difference?


There was a bunch more:


SyntaxError: Unexpected token {
    at Game_Actor.Game_BattlerBase.meetsCustomShowEval (/js/plugins/YEP_SkillCore.js:691:15)
    at Game_Actor.Game_BattlerBase.noHiddenSkillConditionsMet (/js/plugins/YEP_SkillCore.js:678:15)
    at Window_BattleSkill.Window_SkillList.includes (/js/plugins/YEP_SkillCore.js:1118:24)
    at Window_BattleSkill.<anonymous> (/js/rpg_windows.js:2182:25)
    at Array.filter (native)
    at Window_BattleSkill.Window_SkillList.makeItemList (/js/rpg_windows.js:2181:43)
    at Window_BattleSkill.Window_SkillList.refresh (/js/rpg_windows.js:2232:10)
    at Window_BattleSkill.Window_SkillList.setActor (/js/rpg_windows.js:2138:14)
    at Scene_Battle.commandSkill (/js/rpg_scenes.js:2276:23)
    at Scene_Battle.commandSkill


I deleted the first part of the file locations to save space
There is also Array.some(), too. 

Code:
// Returns True or False
// Change stateId to the desired state
$gameParty.members().some(function(a){return a.isStateAffected(stateId)});

// All you should need to do is ...
<Custom Show Eval>
return $gameParty.members().some(function(a){return a.isStateAffected(stateId)});
</Custom Show Eval>
Okay, Yanfly's plugin just does an eval, which is what I expected it would do.  So it's the command that's at fault.


Try this instead:


$gameActors.members().filter( function (actor) { return actor.isStateAffected(x); } ).length > 0


I think I am getting ruby and JS mixed up.
Okay, Yanfly's plugin just does an eval, which is what I expected it would do.  So it's the command that's at fault.


Try this instead:


$gameActors.members().filter( function (actor) { return actor.isStateAffected(x); } ).length > 0


I think I am getting ruby and JS mixed up.

This worked but I had to change $gameActors to $gameParty. Thanks for the help guys  🙂
oh yeah, I forgot that.  I'd just copied & modified my first post.


Wish I'd known about array.some()
$gameActors.members().filter {|actor| actor.isStateAffected(x)}.length > 0


It won't tell you who is affected, just that one or more party members are.


How do I check this in VX ACE?
How do I check this in VX ACE?

This should do:
Ruby:
$game_party.members.any? { |actor| actor.state?(x) }
This should do:
Ruby:
$game_party.members.any? { |actor| actor.state?(x) }

yes, I already found it, than you.

@Ina00 , please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.


Next time, please make a new thread instead, thank you.

Original thread: https://forums.rpgmakerweb.com/threads/script-to-check-if-any-pt-member-has-a-state.67668/