Skip to content

Commit

Permalink
Dungeon loot: Don't crash on unknown items
Browse files Browse the repository at this point in the history
fixes #2228
  • Loading branch information
sfan5 committed Mar 17, 2019
1 parent b853c8a commit 02e2cab
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mods/dungeon_loot/mapgen.lua
Expand Up @@ -88,7 +88,9 @@ local function populate_chest(pos, rand, dungeontype)
amount = rand:next(loot.count[1], loot.count[2])
end

if itemdef.tool_capabilities then
if itemdef == nil then
-- item doesn't exist, do nothing
elseif itemdef.tool_capabilities then
for n = 1, amount do
local wear = rand:next(0.20 * 65535, 0.75 * 65535) -- 20% to 75% wear
table.insert(items, ItemStack({name = loot.name, wear = wear}))
Expand Down

3 comments on commit 02e2cab

@paramat
Copy link
Contributor

@paramat paramat commented on 02e2cab Mar 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes lua check fail.

Checking mods/dungeon_loot/mapgen.lua             1 warning
    mods/dungeon_loot/mapgen.lua:91:22: empty if branch

@Yukitty
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggesting alternative:
if itemdef and itemdef.tool_capabilities then

@paramat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in #2344

Please sign in to comment.