[Solved]Pass multiple entities?

Started by Zefk, July 22, 2018, 01:14:15 AM

Previous topic - Next topic
July 22, 2018, 01:14:15 AM Last Edit: July 22, 2018, 05:36:23 PM by Zefk
Would it be possible to pass more than one entity through a method?

For example,
Code ( lua) Select
entity:overlaps(entity)

Code ( lua) Select
map:get_entites("bomb"):overlaps(test)

July 22, 2018, 11:19:27 AM #1 Last Edit: July 22, 2018, 11:21:14 AM by Diarandor
The function map.get_entities_by_type(type) and other similar functions return an iterator. You can iterate on it to check all collisions at once! (see the Lua API). You can also define your own function, using those functions, and allowing to do things on iterators or lists, but it's not really necessary.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

July 22, 2018, 05:36:06 PM #2 Last Edit: July 22, 2018, 08:26:54 PM by Zefk
@Diarandor
Thank you for pointing me to the function map.get_entities_by_type(type).

I just have to say Solarus is spectacular. It was really that simple. Here is a little working piece of code.

Code ( lua) Select
sol.timer.start(1000, function()
for bomb in map:get_entities_by_type("bomb") do
  if bomb:overlaps(test) then
    test:set_enabled(false)
  end
end
  return true
end)