Multiple Different Items for Conditional Branch

Hello, this is my first post here, apologies for the newbie question.

So I am trying to make a conditional branch that checks if the player has certain items in their inventory (eg. a key, a gem, and a book), and I figured I should use scripts instead of nested multiple conditional branches. Below is the script I made:

$gameParty.hasItem (($dataItems[6]) && ($dataItems[7]) && ($dataItems[8]) && ($dataItems[9]) && ($dataItems[12]))

It's not working though, and instead it only checks if player has any of the items above. What am I doing wrong and how do I fix it? Thank you in advance.

I've moved this thread to Learning Javascript. Thank you.

I think I'd do this with nested branches, personally. 😴

Your script call is equivalent to $gameParty.hasItem($dataItems[12]) because of how JavaScript's && operator works. Instead, you need to call hasItem once per item. Here's a shorthand version for use in Conditional Branch > Script:
JavaScript:
[6,7,8,9,12].every(function(id) { return $gameParty.hasItem($dataItems[id]); })
(Untested, but I think it'll be OK.)

In case you're interested, you can find more info on the logical AND operator here:
...and that every method I've used here:
Sorry about the forum mix-up, I'll post in the correct one next time!

Thank you @caethyril , the code works perfectly! I checked out the links and I learned a lot 🙂
@SodaTears in case you want to check the player for multiple item checks
and avoid nesting or the code @caethyril gave yo which works as well,
but in case you want it shorter and easier, check ConditionalBranch+ plugin,
can check items, armor, weapons, switches, variables etc.

but if you want to avoid to use to many plugins, Caethyril is the best solution by than.
@ShadowDragon Thanks for the recommendation! I might use this for bigger projects but for now I'll study the code 😀

Original thread: https://forums.rpgmakerweb.com/threads/multiple-different-items-for-conditional-branch.130164/