Solarus-Games English Forum

Solarus => Development => Topic started by: Starlock on March 10, 2016, 03:15:10 AM

Title: Entity not working, no error
Post by: Starlock on March 10, 2016, 03:15:10 AM
I'm trying to make a vine entity that can only be destroyed by using fire. There's no error, but the entity doesn't get destroyed when fire is used.
Code ( lua) Select
local entity = ...
local map = entity:get_map()

function entity:on_created()
  self:set_size(16, 16)
  self:set_traversable_by("hero", false)
  self:create_sprite("entities/bush_vine")

    if entity:get_type() == "fire" then
      sol.audio.play_sound("jump")
      self:remove()
   end
end

function entity:on_removed()
  self:get_sprite():set_animation("destroy")
end
Title: Re: Entity not working, no error
Post by: GameboyArda on March 10, 2016, 07:03:24 AM
I would try to use dynamic tiles ???
Title: Re: Entity not working, no error
Post by: Renkineko on March 10, 2016, 07:42:56 AM
I think you missed the collision test, because in your code, you put:

Code (lua) Select

function entity:on_created()
  self:set_size(16, 16)
  self:set_traversable_by("hero", false)
  self:create_sprite("entities/bush_vine")
   
  -- Problem is here : you ask if the entity you created is "fire", but not if it's colliding with fire.
    if entity:get_type() == "fire" then
      ...
    end


I guess it should be (not tested):

Code (lua) Select

function entity:on_created()
  self:set_size(16, 16)
  self:set_traversable_by("hero", false)
  self:create_sprite("entities/bush_vine")
   
  -- Don't know what type of collision use, I think I would put "overlapping" because you want the fire to be on the vine
    entity:add_collision_test("overlapping", function(me, other)
        if other:get_type() == "fire" then
            sol.audio.play_sound("jump")
            me:remove()
        end
    end)
...
Title: Re: Entity not working, no error
Post by: MetalZelda on March 10, 2016, 03:45:35 PM
Yes, there is no collision and no set_traversable_by rules so nothing can collide with
Title: Re: Entity not working, no error
Post by: Renkineko on March 11, 2016, 07:41:33 AM
@MetalZelda : Line 6 of the original code, there is the set_traversable_by rules :)
Title: Re: Entity not working, no error
Post by: MetalZelda on March 11, 2016, 01:46:50 PM
Quote from: Renkineko on March 11, 2016, 07:41:33 AM
@MetalZelda : Line 6 of the original code, there is the set_traversable_by rules :)

Oh yes, my mistake, I didn't see it  :o