Getting event filter results

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
User avatar
y.petremann
Filter Inserter
Filter Inserter
Posts: 438
Joined: Mon Mar 17, 2014 4:24 pm
Contact:

Getting event filter results

Post by y.petremann »

I'm starting to build an event with lots filter case

To summarise to look like this:

Code: Select all

script.on_event(defines.events.on_built_entity, function(event) 
  game.print(serpent.block(event))
end, {
  {filter="type", type="constant-combinator"},
  {filter="ghost_type", ghost_type="constant-combinator"},
  {filter="type", type="train-stop"},
  {filter="ghost_type", ghost_type="train-stop"},
  {filter="rail"},
  {filter="rail-signal"}
})
Some filter are easy to reproduce in the event function, others are not

I would suggest that the event parameter contain a field that give filter results,
it would be a 1-1 map of filters with 2 possible values: true, false
if factorio does minimal evaluation for filters, it can have a nil value if the filter has not been evaluated

here it could give a result like

Code: Select all

{
  consumed_items = "[LuaInventory: temp]",
  entity = "[LuaEntity: train-stop at [gps=157.0,1.0]]",
  name = 6,
  player_index = 1,
  tick = 214527,
  filter_result={
    false,
    false,
    true,
    nil,
    nil,
    nil,
  }
}
which mean it's a train stop

This mean that really big events could use the results of the filters to route to smaller events without reevaluating every filters manually
User avatar
y.petremann
Filter Inserter
Filter Inserter
Posts: 438
Joined: Mon Mar 17, 2014 4:24 pm
Contact:

Re: Getting event filter results

Post by y.petremann »

Also before I was just putting a simple example, but actually I'm trying to make something that would permit to register and dispatch micro events like:

Code: Select all

player_built_entity.register({
  {filter="type", type="constant-combinator"},
  {filter="ghost_type", ghost_type="constant-combinator"}
}, function(event) game.print("You built a constant combinator") end)
player_built_entity.register({
  {filter="type", type="train-stop"},
  {filter="ghost_type", ghost_type="train-stop"}
}, function(event)  game.print("You built a train stop") end)
player_built_entity.register({{filter="rail"}}, function(event)  game.print("You built a rail") end)
player_built_entity.register({{filter="rail-signal"}}, function(event)  game.print("You built a rail signal") end)
the fact is for now I need to reevaluate filters manually

Finally this is not just for the on_build_entity event but for any event with filter
Post Reply

Return to “Modding interface requests”