[Resolved] Table Question
Posted: Mon Jul 02, 2018 5:53 pm
Hi,
I'm not understaning my table return value.
Under initiate I have:
When I create the entity, via a trigger read, I add it to my table like this:
But the values I get from when I print the number of entries in the table start at 0 and the second one is "4" and then it goes to 5, 6, 7...
Why dies it not start at "1" on the first read, since it happens after the first add and then goes to 2, 3, 4...?

I guess the next question is, how do I add to the table each time the conditions are true and how do I remove.
With remove I was using:
But I get "6", then "0", "0", "0". Here I thought it would go from 4 to 0

Not sure what I'm doing wrong here.
Thanks.
I'm not understaning my table return value.
Under initiate I have:
Code: Select all
if global.deployed_mine == nil then
global.deployed_mine = {}
end
Code: Select all
script.on_event(defines.events.on_trigger_created_entity, function(event)
local entity = event.entity
if entity.valid and NELandmine(entity) == "landmine" then
global.deployed_mine[entity.unit_number] = {mine=entity, time=event.tick}
writeDebug(#global.deployed_mine) -- print value
end
end
Why dies it not start at "1" on the first read, since it happens after the first add and then goes to 2, 3, 4...?

I guess the next question is, how do I add to the table each time the conditions are true and how do I remove.
With remove I was using:
Code: Select all
local function On_Death(event)
local entity = event.entity
if entity.valid and NELandmine(entity) == "landmine" then
if global.deployed_mine[entity.unit_number] then
global.deployed_mine[entity.unit_number] = nil
end
writeDebug(#global.deployed_mine) -- print table count
end
end

Not sure what I'm doing wrong here.
Thanks.