GoldenShadowGS wrote:
Paste your code so we can debug it.
Well then. The situation is a bit tangled.
I have an alcove where you have to put an air-essence on to unlock a key. For certain reasons it is possible, that players choose another alcove to put the essence on - but then the essence is locked in that alcove and the player can't get it back (I have put a forcefield over this alcove but you can put items through it if it's on a wall (!) - not if it's alone in the room! But you can't take items back when they are in the forcefield.)
To avoid a dead end I thought it could be a good idea to avoid putting the air essence into the alcove. I have tried to script something: when you put the essence trough the forcefield in the wrong alcove, the essence will be destroyed and recreated in the mouse. But therefore every time another unique item id is created, I cannot destroy the essence in my way. I need a trick to destroy all essenceses regardless which id-number they have.
This is, what I have tried:
Code: Select all
function surfaceContains(surface, item)
for _,i in surface:contents() do
if i.go.name == item then return true
end
end
end
function keepEssence()
if surfaceContains(castle_alcove_key.surface, "essence_air")
then
timer_setMouseEssence.timer:enable() -- timer just delays recreation
--print("timer")
end
end
function setMouse() -- called by timer
for i, ent in castle_alcove_key.surface:contents() do
local obj;
for x=1,100 do
obj = findEntity("
essence_air_"..x..":destroy() --this line seems to be wrong! with 'essence_air_1' it works - but just once...
end
--print("destroy")
end
setMouseItem(spawn("essence_air",nil,nil,nil,nil,nil).item)
--print("create")
end