More entity event hooks

Things that we aren't going to implement
Copern
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Jan 21, 2014 7:56 pm
Contact:

More entity event hooks

Post by Copern »

Looking at Lua/Events in the wiki I notice there only seems to be events for the player or game with the exception of "onentitydied". Something I'd like see is events along the lines of...
  • ontimerstarted (smelters/assemblers/miners) contains Entity
  • ontimerfinished (smelters/assemblers/miners) contains Entity
  • onitemcreate (smelters/assemblers/miners) contains ItemStack
  • oninserterpickup (inserters) contains ItemStack
  • oninserterdrop (inserters) contains ItemStack (or maybe ItemEntity?)
  • onsplit (splitters) contains ItemEntity
Possibly others related to accumulators, turrets, etc. These are just examples of course.

Or perhaps a way to attach functions with specific signatures to prototypes. For example, that function would be called any time that type of entity's timer finishes.
slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: More entity event hooks

Post by slpwnd »

This would add more modding possibilities but we need to be performance aware. Calling the lua code is quite expensive operation. And there can be many inserters in a big factory calling on pickup every tick. Hmmm but I suppose often you would be interested (for the modding) in calling this only for specific (a few) machines right? That would be doable, because when the event handler is created it could specify an entity filter to be applied to.
User avatar
Dysoch
Filter Inserter
Filter Inserter
Posts: 445
Joined: Fri Oct 18, 2013 2:27 pm
Contact:

Re: More entity event hooks

Post by Dysoch »

Onitemcreate is something i want badly. Right now my dynamic system only works with hand crafted items, and only with the item itself.

Could the onplayercrafteditem event be changed to also include the intermediates needed for an item?
Creator of:
- DyTech
- DyWorld
- DyWorld-Dynamics
- DyWorld-Dynamics 2
Active since Factorio 0.6
Copern
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Jan 21, 2014 7:56 pm
Contact:

Re: More entity event hooks

Post by Copern »

slpwnd wrote:This would add more modding possibilities but we need to be performance aware. Calling the lua code is quite expensive operation. And there can be many inserters in a big factory calling on pickup every tick.
I understand, I assumed that would be an issue. The oninserterpickup was probably a bad example. I figured I would throw those in there anyway since it's something that would be nice to have.
slpwnd wrote:Hmmm but I suppose often you would be interested (for the modding) in calling this only for specific (a few) machines right? That would be doable, because when the event handler is created it could specify an entity filter to be applied to.
That is correct, I'd only want to be subscribed to events coming from specific types of entities. No sense for all factories to invoke events when a modder only wants to know the ones from his/her custom factories, right?

Oh, onitemcreate could also contain the entity that created the item.
SilverWarior
Filter Inserter
Filter Inserter
Posts: 559
Joined: Mon Mar 04, 2013 9:23 am
Contact:

Re: More entity event hooks

Post by SilverWarior »

Is it posible to dynamically assign LUA methods to certain events?
In Objective Pascal events are defined as objects which point to event methods. So when event is fired a quick check is made to see if Event method has been assigned. If it was assignesd method is executed if not nothing happens. So there is practically no performance loss when you have lots of events which doesn't have assigned event methods to them.
Copern
Burner Inserter
Burner Inserter
Posts: 10
Joined: Tue Jan 21, 2014 7:56 pm
Contact:

Re: More entity event hooks

Post by Copern »

SilverWarior wrote:Is it posible to dynamically assign LUA methods to certain events?
That's what I proposed in the OP.
Copern wrote:Or perhaps a way to attach functions with specific signatures to prototypes. For example, that function would be called any time that type of entity's timer finishes.
Basically you would define functions for events in the prototype. If there was no function defined in the prototype, you could avoid the lua call entirely.
Post Reply

Return to “Won't implement”