Closed Diarandor closed 6 years ago
I have tested this again and I strongly believe that this only happens when the collision is with a sprite of the other_entity that is not the main sprite. When the sprite of the other_entity in the collision is its main sprite, the order is the one mentioned in the Lua API.
Check the shield script in the repo of CoS, lines 283-284, where this bug is mentioned: https://github.com/solarus-games/children-of-solarus/blob/dev/data/items/shield.lua There I used a workaround, but if you comment those lines, the bug will reappear.
To reproduce the error with the custom shield of CoS, follow these steps (and see https://github.com/solarus-games/children-of-solarus/blob/dev/data/items/shield.lua):
0) The collision test of the shield is defined on the shield_collision_mask custom entity. You may need to read part of the code of the script to understand what I explain below.
1) First, notice that in line 280 I have interchanged the names of the sprites (entity_sprite and shield_sprite) in the wrong position of the function because otherwise the code of my custom shield would not work. The variable entity_sprite has should have the sprite of the shield_collision_mask (because the collision test is defined there). However, the variable entity_sprite is getting both values with collisions: the collision mask sprite and enemy sprites too, which should not happen (there must be a bug). To check that both cases are happening, follow next step and use the shield on an enemy (I don't remember if this happens only for enemies with several sprites or for all enemies).
2) Replace line 284 with this code to print that info and check what I say above:
if entity_sprite:get_animation_set() ~= "hero/shield_collision_mask" then
print(entity_sprite:get_animation_set())
end
or with this code to see the other info:
if entity_sprite:get_animation_set() == "hero/shield_collision_mask" then
print(entity_sprite:get_animation_set())
end
Ok, this is an easier way to test this bug. Steps to reproduce it (use the repo of CoS): -Create an enemy and a custom entity in the map with the codes below and put them overlapping themselves. You will see both print messages at the same time, which should not happen. -Script for enemy:
function enemy:on_created()
local sprite1 = self:create_sprite("enemies/diarandor/goblin_green")
sprite1:set_animation("walking")
end
-Script for custom entity:
function entity:on_created()
local sprite = self:create_sprite("enemies/diarandor/chameleon")
sprite:set_animation("walking")
self:add_collision_test("sprite", function(this, other, this_sprite, other_sprite)
if this_sprite:get_animation_set() == "enemies/diarandor/chameleon" then
print("YEAH!")
else
print("NOPE!")
end
print(this_sprite:get_animation_set())
end)
end
I think that the callback parameters in sprite collision tests for custom entities are wrong. The API says that the third and fourth parameters are, respectively, the sprites of the custom entity and the other entity. However, the order of this two sprites is given in wrong order.
Lua API: