Check if a specific set of weapons is owned by the party

eomereolsson

Veteran
Veteran
Joined
Sep 29, 2021
Messages
173
Reaction score
144
First Language
German
Primarily Uses
RMMV
Well, one thing that definitely won't work are your examples 4 and 5. The function @caethyril provided tries to convert the notetag to a number and compares whether it is greater to or equal to 1. If you throw a text in there, that will obviously cause problems. If you want to compare the text of the notetag to some other text, try the following:
JavaScript:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && item.meta && item.meta.Strenght.trim() == 'Strong'; }); });
This will be true if any actor in the party has at least one weapon equipped with the notetag <Strenght: Strong>

Your other examples should work fine, theoretically. However I don't think you altered the statements in a way that actually accomplishes what you are trying to accomplish. (That is a bit hard to tell as you only told us how you altered them and that the do not work as intended, but didn't tell us what you intended). You altered the second argument that gets passed to parseInt(). This only alters to which number system the given text gets converted.
For example the content of the notetag <x: 101>, when passed through parseInt(item.meta.x, 10) would be the number 101 (1*100 + 0*10 + 1*1 or 1*10^2 + 0*10^1 + 1*10^0)in the decimal system (the normal number system that you are used to).
When passed through parseInt(item.meta.x, 2) it would still be the number 101, but in the binary system - or 5 in the decimal system(1*4 + 0*2 + 1*1 or 1*2^2 + 0*2^1 + 1*2^0).

I suspect you didn't want to alter how the notetag is converted to a number, but how that number in the notetag gets compared. That happens directly after that.
JavaScript:
//[...]
parseInt(item.meta.Strenght, 10) >= 1;
//[...]
If you want to check whether at least one actor in the party has a weapon with 5 Strenght or more, then you would replace the 1 with a 5.
If you want to change how both numbers are compared, you can change the operator for that, too. Instead of >= put:
- <= for less then or equal
- == for exactly equal
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
231
Reaction score
58
First Language
English
Primarily Uses
RMMV
Ooh now I understand, completely skipped the Parse part, just copypasted blindlessly the code and was thinking it was just a check of meta cypher to cypher. Now I understand totally, thanks for helping!
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,546
Reaction score
2,665
First Language
EN
Primarily Uses
RMMZ
JavaScript:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && item.meta && item.meta.Strenght.trim() == 'Strong'; }); });
By default the meta property is added to all note-bearing database items, so there shouldn't be a need to check for its existence. However, item.meta.Strenght might be a non-string value:
  • undefined if that weapon does not have a Strenght notetag;
  • true if that weapon has a tag with no value, e.g. <Strenght> rather than <Strenght: 10>.
In these cases there is no trim method available, which will cause an error. Instead, I'd consider something like this:

$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && String(item.meta.Strenght || '').trim() === "Strong"; }); });
I.e. convert to string first to avoid errors, then trim. (String(undefined) returns "undefined", hence the || '' just in case.)

[Edit: corrected weapon -> item.]
 
Last edited:

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
231
Reaction score
58
First Language
English
Primarily Uses
RMMV
Nice suggestion, however it was working before, with the:

Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(item) { return item && item.meta && item.meta.Strenght.trim() == 'Strong'; }); });

While unfortunately it doesn't work with your:
Code:
$gameParty.members().some(function(actor) { return actor.weapons().some(function(weapon) { return item && String(item.meta.Strenght || '').trim() === "Strong"; }); });


Notebox is:
<Strenght: Strong>
 

eomereolsson

Veteran
Veteran
Joined
Sep 29, 2021
Messages
173
Reaction score
144
First Language
German
Primarily Uses
RMMV
undefined if that weapon does not have a Strenght notetag;
That scenario I was trying to prevent. But somehow I wrote ... && item.meta && ... instead of ... && item.meta.Strenght && ....
true if that weapon has a tag with no value, e.g. <Strenght> rather than <Strenght: 10>
And I completely forgot to catch that scenario :rswt
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,546
Reaction score
2,665
First Language
EN
Primarily Uses
RMMZ
@joket: oops, I wrote weapon for the argument but item within the actual function. I edited my previous post with a correction, sorry~ :kaoswt:
 

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
231
Reaction score
58
First Language
English
Primarily Uses
RMMV
Works perfectly thank you
 

Latest Threads

Latest Profile Posts

Genuinely considering making a thread informing people how to Google.
It's time for Da Update...

Prototyping some overworld abilities. Some of the characters you'll meet on your journey can use special overworld skills to travel around. This can be something like digging holes in the ground or getting hints towards your next objective.

Even more things I made.
Equipping Abilities is very important.
fLhHhZjh.gif
demonow.jpg

Eniko: Ghosts Of Grace Alpha Demo is Officially LIVE on Steam!

>> DOWNLOAD AND PLAY THE DEMO ON STEAM NOW!

Forum statistics

Threads
122,152
Messages
1,146,863
Members
160,419
Latest member
EllieFigure8
Top