Setting a variable based on multiple different items?

In my Moltres Rider game, I have the party collecting gems by defeating Cruel Beasts boss fights in order to reveal the hidden lair of the final Cruel Beast in the Winchell World story arc.

I want the party to talk to a certain researcher in a town to gain information on these gems. However, the player can have anywhere from 2 - 7 gems at this point.

Each gem is a different item with a different name.

To make the dialogue flow, I want the dialogue to specify number of these gems that the party has.

The item IDs for the six gems are 191, 192, 194, 199, 200, 202 (one gem is obtained through story (ID 188) before the entire world opens up, and a switch tells the game that the party has collected at least one more, but which one could be any of the other six)

Is there a script call when setting up the variable that I can set the variable to be the total number of how many of item ID 188, 191, 192, 194, 199, 200, 202 the player has?

I know that I can just use the "add" function but I figure I would check to see if it can be done with only one "control variable" first.
Code:
gems = [188,191,192,194,199,200,202]
$game_variables[1] = 0
gems.each do |i|
item = $data_items[i]
$game_variables[1] += 1 if $game_party.has_item?(item)
end
1699020354049.png

Change the variable number to the one you want to use.
I think the normal way to do this would probably be to get rid of this switch:
a switch tells the game that the party has collected at least one more, but which one could be any of the other six
And replace it with a variable. Just add one to the variable, every time the player collects a gem. Then, any time you simply need to know whether or not the player has collected at least one gem, you just check if the value of the variable is greater than 0 (or greater than 1 if you're wanting to know whether they've collected the first gem + at least one more). And if you need the total number of gems collected, you already have it sitting right there in the variable.
Code:
gems = [188,191,192,194,199,200,202]
$game_variables[1] = 0
gems.each do |i|
item = $data_items[i]
$game_variables[1] += 1 if $game_party.has_item?(item)
end
View attachment 282434
Change the variable number to the one you want to use.
This does not work for me! The NPC always says that I have 0 despite the fact that I have 7 gems.
This does not work for me! The NPC always says that I have 0 despite the fact that I have 7 gems.
as always, you're either doing something wrong or your project that you started from a pirate copy of vx ace is still messing things up.

The post I made is from a 100% working solution, tested on a new project.
First of all, can you tell us if you were using the game variable #1 in a parallel process of sorts or in a common event?
I'm not implying it necessarily took place in your project, I just trying to find out if there's a chance something can happen between the script calls and the execution of the message window's contents.
Does it display a different value if you pick a different variable ID by any chance? This should be changed in both the script calls and the message window.
I was doing something wrong. I noticed that the variable is mentioned twice in that script and I only changed the variable number for the first mention.

Original thread: https://forums.rpgmakerweb.com/threads/setting-a-variable-based-on-multiple-different-items.162633/