However, this particular problem, which should be a simple script, has me completely baffled as to why it crashes only under certain conditions.
Here is the script and here's what's happening.
Code: Select all
function checkAlcoveForItems() -- change these variables to match your alcove's ID and the item you want to test for local itemName1 = "blue_gem" local alcoveID1 = temple_alcove_5 local itemName2 = "frostbite_necklace" local alcoveID2 = temple_alcove_6 counter = 0 -- iterate through all the contained items on alcove, checking for a matching name for i in alcoveID1:containedItems() do if i.name == itemName1 then itemFound1() end end for i in alcoveID2:containedItems() do if i.name == itemName2 then itemFound2() end end end -- run this script _once for each item_ with a matching name function itemFound1() counter = counter+1 if counter == 2 then temple_door_iron_2:open() end function itemFound2() counter = counter+1 if counter == 2 then temple_door_iron_2:open() end -- run this script _once for each item_ without a matching name end end
1. If I put the items in the correct alcove, script works perfectly. Door opens.
2. If I put the items in the wrong alcoves, script works perfectly. Door stays closed.
Here is where things get wonky.
3. If I, after putting the items in the wrong alcove, remove them and then place the correct item in alcove_5, I get a script crash that reads.
'attempt to call global 'itemfound2' (a nil value) x
Why? Totally stumped.