Page 1 of 1
More stupid questions: loading_list, and entity destruction
Posted: Sat Mar 19, 2016 5:03 am
by ibanix
So more of me trying to screw around with t-engine and getting lost.
Today's questions:
1) What exactly is loading_list? It seems to be able to be used to reference entities that have already been loaded from a file?
2) How do I delete an entity? In this case, I'm try to have an addon delete an ego from the list of possible egos. Is there a way I can reference a table and then remove it from the table?
Thanks!
Re: More stupid questions: loading_list, and entity destruct
Posted: Mon Mar 21, 2016 1:44 am
by Zizzo
ibanix wrote:1) What exactly is loading_list? It seems to be able to be used to reference entities that have already been loaded from a file?
[sound F/X: source diving] That's some magic done by Entity:loadList(). If you're in a file being loaded by Entity:loadList(), loading_list will be a reference to the list of entities being loaded.
ibanix wrote:2) How do I delete an entity? In this case, I'm try to have an addon delete an ego from the list of possible egos. Is there a way I can reference a table and then remove it from the table?
You can do this from an 'Entity:loadList' hook. In your hooks/load.lua, add something like:
Code: Select all
class:bindHook('Entity:loadList', function(self, data)
-- data.file is the name of the file being loaded.
if data.file == '/data/general/objects/egos/file-that-defines-the-ego-you-want-to-remove.lua' then
-- data.res is the table into which entities are being loaded; you can manipulate
-- it to alter or remove entities.
for i, e in ipairs(data.res) do
if e.name == 'the ego you want to remove' then
table.remove(data.res, i)
break
end
end
end
end)
For comparison, I do something like this in
Worms Don't Walk.
Re: More stupid questions: loading_list, and entity destruct
Posted: Mon Mar 21, 2016 3:09 am
by ibanix
Zizzo, once again you are the man. Thank you.