I have one that kinda works. There is no way to get the torches that are in the holder directly, but we can get all torches at the location that contains the holder, including torches in the holder. A first approach would be something like:
When a torch is added, run a function that checks for at an everburning torch at the the location with the holder, just like checking an alcove. If we find one, open the door.
This has a big problem, though. There is no way to determine if the torch is in the holder or if it is just sitting on the ground and a normal torch was put in the holder.
We can fix this by getting a bit more complicated:
- Find all everburning torches at the location of the holder
- Destroy each torch, one at a time
- Check if the torch holder is no longer activated
- If the holder is empty, then the destroyed torch was in the holder, open the door
- if the holder is still filled, then the destroyed torch was on the ground, move on to the next torch
- Respawn the torch in the holder or on the ground as appropriate
I see a couple downsides to this. Firstly, it creates new torches, essentially wasting an Id. Secondly, I can't figure out a way to get the subtile offset for the torch when it is on the ground; so respawning on the ground causes the torch to appear to "jump"
Wire the following to a torch's activate event and change the torchDoor:open() to be your door:
Code: Select all
-- Lock to prevent adding/removing torches from causing a infinite loop.
locked = false
function CheckTorch(holder)
-- Prevent an infinite loop
if locked then
return
end
-- Make a list of all torches at the holder's location. We can't loop
-- over the items directly because we are going to change the entities
-- at the current cell
local eTorches = {}
for item in entitiesAt(holder.level, holder.x, holder.y) do
if item.name == "torch_everburning" then
table.insert(eTorches, item)
end
end
locked = true
-- Loop over the everburning torches at the location.
for i, torch in ipairs(eTorches) do
local torchFacing = torch.facing
-- Destroy the torch. If the torch was in the holder, the holder
-- should now be empty.
torch:destroy()
if not holder:hasTorch() then
-- holder is empty, the torch was in the holder. We can
-- then open the door, recreate the torch, and break out
-- of the loop.
torchDoor:open()
holder:addItem(spawn("torch_everburning"))
break
else
-- if the holder still has the torch, then the everburning torch
-- was not in the holder. we then create a new torch on the ground
-- to replace the one we destroyed
spawn("torch_everburning", holder.level, holder.x, holder.y, torchFacing)
end
end
locked = false
end
Note that nothing fancy is needed for deactivation, just wire torch holder to close the door on deactivation.