I was looking at the Array.prototype.map() method but I couldn't quite figure out which function to pass...I can reference an individual item's notedata with $dataItems[1].note, but haven't been able to figure out how to check the entire $dataItems array.
I was trying a for loop:
JavaScript:
for (var i = 1; i < $dataItems.length; i ++) { var note = $dataItems[i].note;}
but I was getting a 'cannot read property "note" of null.
So I tried:
JavaScript:
for (var i = 1; i < $dataItems.length; i ++) { if ($dataItems[i].note !== null) {var note = $dataItems[i].note;}}
-Pre-Post Edit-
I realized that using Yanfly's item core extends $dataItems.length beyond 2000 and that is where the null was coming from.
Using:
JavaScript:
for (var i = 1; i < 2001; i ++) {
if ($dataItems[i].note !== null) {
var note = $dataItems[i].note;
if (note.includes('array test>')) {
array.push($dataItems[i].id)}
}
};
I was able to create a new array that contains the item Id's of any item with <array test> in it's notetag!
Thank you for the inspiration‼
Now, I can give my items, weapons and armors custom notetags to group them together in various ways and award them accordingly!
While I still fully support organizing the database, this will definitely add a dynamic layer to my project,
thanks again!
Also, I realize that I could probably do the random sword-type reward without the custom notetag, considering the nature of the preexisting weapon types, but that was just a simple example to make it easier to realize. My current thoughts on how to implement this align more with the idea of making 'sub-categories' such as:
- Items that could be secondary fishing rewards, such as seaweed or wood,
- Ingredients from a particular dish or crafting recipe,
- Linking particular gems to particular ores as potential secondary rewards when mining,
- The party leaders preferred food, giving incentive to swap leaders.
I also see this being a great way to have loot pools that award random loot but remove the item from the pool after awarding it.
These tutorials are absolutely helping me expand my knowledge and abilities!