Solarus-Games English Forum

Solarus => Development => Topic started by: Yosha on July 16, 2015, 08:45:01 AM

Title: custom_entity and sprite event
Post by: Yosha on July 16, 2015, 08:45:01 AM
Hello, like many users here, I made a custom entity that follow the hero (it's the main gameplay of my project since many years I'm working on!) but I have some little troubles with it. It moves, throught stairs, hole or whatever, and I can change the sprite animation, but when I want to came back to normal, after the animation finished, I have an error.

Here is an example : P1 is the hero and P2 the follower


function P2:on_ground_below_changed(ground_below)
if ground_below == "hole" then
game:set_value("P2_state", "falling")
P2_Move:stop()
if P2:get_sprite():get_animation() ~= "falling" then
P2:get_sprite():set_animation("falling")
P1:freeze()
end
function P2:get_sprite():on_animation_finished("falling")
game:set_value("P2_state", "free")
P1:unfreeze()
end
end
end


Now there's the error :
Error: Failed to load script 'entities/P2': [string "entities/P2.lua"]:220: unexpected symbol near ':'
Error: In entities/P2: attempt to call a string value

The problem seems to be : function P2:get_sprite():on_animation_finished("falling")   

I have another problem with the jump (it works once and doesn't work after) but we'll see that later !
Thanks for the help!
Title: Re: custom_entity and sprite event
Post by: Christopho on July 16, 2015, 08:50:07 AM
It is a syntax error:
Code (lua) Select
function P2:get_sprite():on_animation_finished("falling")
should be
Code (lua) Select
local p2_sprite = P2:get_sprite()
function p2_sprite:on_animation_finished("falling")
Title: Re: custom_entity and sprite event
Post by: Yosha on July 16, 2015, 09:24:21 AM
OK thank you for the quickness! But I tried it and it doesn't work too.
I have another error :
Error: Failed to load script 'entities/P2': [string "entities/P2.lua"]:183: <name> or '...' expected near '"falling"'
Error: In entities/P2: attempt to call a string value

I found a trick but it's not what I want to do, and it would be fine while the animation is no longer that the timer...

sol.timer.start(1000, function()
function P2:get_sprite():on_animation_finished("falling")
game:set_value("P2_state", "free")
P1:unfreeze()
end)
Title: Re: custom_entity and sprite event
Post by: Christopho on July 16, 2015, 09:58:15 AM
Ooops, sorry, there is still an obvious syntax error. I think you meant:
Code (lua) Select

local p2_sprite = P2:get_sprite()
function p2_sprite:on_animation_finished(animation)
    if animation == "falling" then
        ...
    end
end
Title: Re: custom_entity and sprite event
Post by: Yosha on July 16, 2015, 12:13:52 PM
Thank You ! It works now ! And above that, I found out why my Custom entity did only one jump before bugging... I created 2 movement : one for the normal moving (walking and stop), and one for the jump. And after a week of thinking, testing, and headache, I realized that only one was necessary.   :-\

However, I have another question about the diagonal jumper : I saw that the overlapping part is not only the blue bar viewed on the editor, but the green square when you select it(i think it's the bounding box) and when I use custom_entity:set_can_traverse([entity_type], traversable) like this example:
P2:set_can_traverse("jumper", function() game:set_value("P2_state", "jumping") end)
the state jumping begins when P2 overlaps the square and not only the jumper (blue bar) itself. So, I wondering if it was a kind of bug from solarus or if it was normal. Therefore I found a solution by changing the P2_state not with the jumper (too bad!) but when the hero state changed. Thanks for all and it the last time I disturb you today !
Title: Re: custom_entity and sprite event
Post by: Christopho on July 16, 2015, 12:34:31 PM
I'd say that this is a bug, you can report it on https://github.com/christopho/solarus/issues/new
Title: Re: custom_entity and sprite event
Post by: Yosha on July 16, 2015, 12:56:19 PM
Ok, it's done!