Hello, im trying to make code that goes through a database with about 90 items in it and automatically applies a letter based off the rarity of the item is. I want it to label it for me however when i run the code it only runs for 1 item and then when it attempts to go to the next item it gives me an error.
Here is my code:
$w("#StartButton").onClick(()=>{
let count = $w("#dataset1").getTotalCount(); // 23
var v = 0;
for (var i=0;i<count;i++) {
$w("#dataset1").onReady( () => {
$w("#dataset1").setCurrentItemIndex(i);
});
let itemObj = $w("#dataset1").getCurrentItem();
var itemRare = itemObj.rarity;
var name = itemObj.title;
console.log("Item num " + i + " Rarity: " + itemRare + " Name: " + name)
if (itemRare == "Common") {
$w("#dataset1").setFieldValue("sortTitle", "Z");
$w("#dataset1").save();
console.log("ITEM SAVED ");
}
if (itemRare == "Uncommon") {
$w("#dataset1").setFieldValue("sortTitle", "L");
$w("#dataset1").save();
console.log("ITEM SAVED ");
}
if (itemRare == "Rare") {
$w("#dataset1").setFieldValue("sortTitle", "K");
$w("#dataset1").save();
console.log("ITEM SAVED ");
}
if (itemRare == "Epic") {
$w("#dataset1").setFieldValue("sortTitle", "J");
$w("#dataset1").save();
console.log("ITEM SAVED ");
}
if (itemRare == "Legendary") {
$w("#dataset1").setFieldValue("sortTitle", "J");
$w("#dataset1").save();
console.log("ITEM SAVED ");
}
if (itemRare == "Shadow Series") {
$w("#dataset1").setFieldValue("sortTitle", "I");
$w("#dataset1").save();
console.log("ITEM SAVED ");
}
if (itemRare == "Icon Series") {
$w("#dataset1").setFieldValue("sortTitle", "C");
$w("#dataset1").save();
}
if (itemRare == "Star Wars Series") {
$w("#dataset1").setFieldValue("sortTitle", "G");
$w("#dataset1").save();
}
if (itemRare == "DC SERIES") {
$w("#dataset1").setFieldValue("sortTitle", "F");
$w("#dataset1").save();
}
if (itemRare == "MARVEL SERIES") {
$w("#dataset1").setFieldValue("sortTitle", "E");
$w("#dataset1").save();
}
if (itemRare == "DARK SERIES") {
$w("#dataset1").setFieldValue("sortTitle", "D");
$w("#dataset1").save();
}
if (itemRare == "Lava Series") {
$w("#dataset1").setFieldValue("sortTitle", "B");
$w("#dataset1").save();
}
if (itemRare == "Frozen Series") {
$w("#dataset1").setFieldValue("sortTitle", "A");
$w("#dataset1").save();
}
}
i++
});
I’ve tried to search it up online however there’s no simple fix that works for my situation. Is it possible to fix it?