Author Topic: [Solved]Pass multiple entities?  (Read 186 times)

Zefk

  • Hero Member
  • *****
  • Posts: 536
  • Just helping Solarus
    • View Profile
    • Zelzec
[Solved]Pass multiple entities?
« on: July 22, 2018, 01:14:15 am »
Would it be possible to pass more than one entity through a method?

For example,
Code: Lua
  1. entity:overlaps(entity)

Code: Lua
  1. map:get_entites("bomb"):overlaps(test)

Diarandor

  • Hero Member
  • *****
  • Posts: 1020
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Pass multiple entities?
« Reply #1 on: July 22, 2018, 11:19:27 am »
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.
« Last Edit: July 22, 2018, 11:21:14 am by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Zefk

  • Hero Member
  • *****
  • Posts: 536
  • Just helping Solarus
    • View Profile
    • Zelzec
Re: [Solved]Pass multiple entities?
« Reply #2 on: July 22, 2018, 05:36:06 pm »
@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
  1. sol.timer.start(1000, function()
  2. for bomb in map:get_entities_by_type("bomb") do
  3.   if bomb:overlaps(test) then
  4.     test:set_enabled(false)
  5.   end
  6. end
  7.   return true
  8. end)