More stupid questions: loading_list, and entity destruction

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
ibanix
Wyrmic
Posts: 244
Joined: Thu May 23, 2013 12:25 am

More stupid questions: loading_list, and entity destruction

#1 Post 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!
Please help with the ToME wiki!

Zizzo
Sher'Tul Godslayer
Posts: 2521
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

Re: More stupid questions: loading_list, and entity destruct

#2 Post 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.
"Blessed are the yeeks, for they shall inherit Arda..."

ibanix
Wyrmic
Posts: 244
Joined: Thu May 23, 2013 12:25 am

Re: More stupid questions: loading_list, and entity destruct

#3 Post by ibanix »

Zizzo, once again you are the man. Thank you.
Please help with the ToME wiki!

Post Reply