Solarus-Games English Forum

Solarus => Development => Topic started by: Zefk on July 22, 2018, 01:14:15 AM

Title: [Solved]Pass multiple entities?
Post by: Zefk 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) Select
entity:overlaps(entity)

Code ( lua) Select
map:get_entites("bomb"):overlaps(test)
Title: Re: Pass multiple entities?
Post by: Diarandor 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.
Title: Re: [Solved]Pass multiple entities?
Post by: Zefk on July 22, 2018, 05:36:06 PM
@Diarandor
Thank you for pointing me to the  function map.get_entities_by_type(type) (http://www.solarus-games.org/doc/latest/lua_api_map.html#lua_api_map_get_entities_by_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)