I am getting a monster to take an item out of a chest. This is my exact code to do that:
Code: Select all
for i, item in chestGO.surface:contents() do
for j, id in ipairs(bd.holdableObjects) do
if item.go.id == id then
print("Monster: "..brain.go.id.." is taking key: "..item.go.id.." out of chest")
brain.go.monster:addItem(item)
end
end
end
Later, he choses to go back to the chest and take anything in there out again. The exact same code executes. What should happen is chestGO.surface:contents() should not be returning any more objects since he already took the key out. But the key is still there. And he takes it again!! The exact same key.
I kill the monster and the game blows up because it tries to put two identical keys on the ground. Its bugged.
Error:
Code: Select all
[string "Map.lua"]:0: entity already added to map
stack traceback:
[C]: in function 'assert'
[string "Map.lua"]: in function 'addEntity'
[string "Monster.lua"]: in function 'dropItem'
[string "Monster.lua"]: in function 'dropAllItems'
[string "Monster.lua"]: in function 'die'
[string "GameMode.lua"]: in function 'keyPressed'
[string "DungeonEditor.lua"]: in function 'preview'
[string "DungeonEditor.lua"]: in function 'update'
[string "Grimrock.lua"]: in main chunk