On_PrePlayer_Mined_Entity entity cannot be table.removed?
Posted: Tue Jul 21, 2015 3:52 pm
Hey guys, Im working at a simple teleporter mod. I already did all the mechanics such as linking teleporters with a specific tool and going through the teleporters, but now I got a problem.
So I carry all teleporter links inside a table called "links". A entry inside this table looks like this: links[1] = {a=teleporter_entity_1, b=teleporter_entity_2}.
Nothing special. But now I need to break a teleporter link once I mine a teleporter. So I think the right event for that would be the On_PrePlayer_Mined_Entity cause it gives me the entity which Im going to remove, unlike the On_Player_Mined_Item . I need this entity handle to remove it from the links. So heres the code:
The isLinked function:
The breakLinks function:
So that should remove first the opposite linked teleporter with findBside and then the entity itself, and I gave it the event.entity variable coming from the event, but it keeps saying:
Can anybody help me? Thanks!
Edit: Oh and does anybody know how I can story the links within the map so I dont need to relink those portals at every load again?
So I carry all teleporter links inside a table called "links". A entry inside this table looks like this: links[1] = {a=teleporter_entity_1, b=teleporter_entity_2}.
Nothing special. But now I need to break a teleporter link once I mine a teleporter. So I think the right event for that would be the On_PrePlayer_Mined_Entity cause it gives me the entity which Im going to remove, unlike the On_Player_Mined_Item . I need this entity handle to remove it from the links. So heres the code:
Code: Select all
game.on_event(defines.events.on_preplayer_mined_item,
function(event)
game.player.print(tostring(event.entity.name))
if event.entity.name == "TeleporterEntity" then
if isLinked(event.entity) then
game.player.print("link detected! breaking...")
breakLinks(event.entity)
end
end
end
)
Code: Select all
function isLinked(teleporter)
state = false
for k,v in ipairs(links) do
if teleporter == links[k].a or teleporter == links[k].b then
state = true
end
end
return state
end
Code: Select all
function breakLinks(someTeleporter)
if isLinked(someTeleporter) then
table.remove(links, findBside(someTeleporter))
table.remove(links, someTeleporter[1])
end
end
Code: Select all
Error while running the event handler: __Stuff__/control.lua:46: bad argument #2 to 'remove' (number expected, got table)
Edit: Oh and does anybody know how I can story the links within the map so I dont need to relink those portals at every load again?