ultrakorne / better-rolltables

Module for FoundryVTT to improve rolltables
MIT License
32 stars 29 forks source link

createTableFromCompendium Result in error #152

Closed rinnocenti closed 2 years ago

rinnocenti commented 2 years ago

image betterTables.createTableFromCompendium result in error. it creates the table, but with the wrong weights and ranges

game.betterTables.createTableFromCompendium("Full Table items",
    "dnd5e.items",
    { weightPredicate: predicate }
);

function predicate(entity) {
    switch (entity.data.data.rarity) {
        case "Common":
            return 16;
        case "Uncommon":
            return 8;
        case "Rare":
            return 4;
        case "Very rare":
            return 2;
        case "Legendary":
            return 1;
        default:
            return 0;
    }

}
DanielBoettner commented 2 years ago

I will look into it. Still have some features in my local dev that need polishing. I will add a bugfix for that.

DanielBoettner commented 2 years ago

I found the error.

The check for 0 was faulty as it did not check on the weight but the item. This resulted in 0 values in the table which is not allowed.

If you want to correct that error locally as long as the next release isn't ready. you may correct this https://github.com/ultrakorne/better-rolltables/blob/master/scripts/better-tables.js#L175 line.

Just change it from results.filter(x => x !== undefined) to results.filter(x => x.weight !== 0)

However. For your call to work, the cases should be (lower) camelCase. As entity.data.data.rarity is (lower) camelCase.

This is wrong in the Wiki and should be corrected.

Also, I will ask @ultrakorne if he can add me as an collaborator to the project. So I can change things like these.

function predicate(entity) {
    switch (entity.data.data.rarity) {
        case "common":
            return 16;
        case "uncommon":
            return 8;
        case "rare":
            return 4;
        case "veryRare":
            return 2;
        case "legendary":
            return 1;
        default:
            return 0;
    }
}