Hello,
I was working on some items and I am currently facing a weird issue
local variant = item:get_variant()
local game = item:get_game()
local map = item:get_map()
local hero = item:get_game():get_hero()
local tunic = game:get_ability("tunic")
hero:freeze()
game:set_pause_allowed(false)
if variant == 1 then -- swing, detectors are here
hero:set_tunic_sprite_id("hero/item/bottle/bottle.swing.tunic_"..tunic)
hero:set_animation("stopped")
if math.random(1) == 0 then
sol.audio.play_sound("items/bottle/swing0")
else
sol.audio.play_sound("items/bottle/swing1")
end
local x, y, layer = hero:get_position()
local direction4 = hero:get_direction()
if direction4 == 0 then x = x + 12
elseif direction4 == 1 then y = y - 12
elseif direction4 == 2 then x = x - 12
else y = y + 12
end
local bottle = map:create_custom_entity{
x = x,
y = y,
layer = layer,
width = 8,
height = 8,
direction = direction4,
}
bottle:set_origin(4, 5)
sol.timer.start(200,function()
bottle:add_collision_test("overlapping", function(bottle, other)
if other:get_type() == "pickable" and direction4 == bottle:get_direction() then
print("it's a pickable")
sol.audio.play_sound("items/bottle/close")
bottle:clear_collision_tests()
hero:set_tunic_sprite_id("hero/tunic"..tunic)
hero:unfreeze()
bottle:remove()
self:set_finished()
else
print("it's not a pickable")
end
end)
end)
sol.timer.start(300,function()
hero:set_tunic_sprite_id("hero/tunic"..tunic)
hero:unfreeze()
bottle:remove()
self:set_finished()
end)
The script works well, but the main issue is the collision test.
The script check if the custom entity is colliding with a pickable and does currently nothing else than display a message on the console.
But, weird thing is, the script, even if the custom entity is on any pickable, display "not a pickable", and the custom entity is only enabled if the hero is facing north, despite the "direction = direction4" (hero:get_direction()).
I did though of metatable, but I don't know how these works
bottle:add_collision_test("overlapping", function(bottle, other)
if other:get_type() == "pickable" then
print("it's a pickable")
sol.audio.play_sound("items/bottle/close")
bottle:clear_collision_tests()
hero:set_tunic_sprite_id("hero/tunic"..tunic)
hero:unfreeze()
bottle:remove()
self:set_finished()
else
print("it's not a pickable")
end
(http://i.imgur.com/ZOyOA49.png)
(http://i.imgur.com/AgN0kRn.png)
Can you display the type of the other entity instead of just "not a pickable"?
Also, try with the new version 1.4.5 that was released yesterday. Some issues related to collisions with custom entities were fixed.
Quote from: Christopho on November 23, 2015, 01:30:28 PM
Can you display the type of the other entity instead of just "not a pickable"?
Also, try with the new version 1.4.5 that was released yesterday. Some issues related to collisions with custom entities were fixed.
This was just a test to see if the custom entity collision works when it reach any pickable, the rest of the script is just the other bottle variant, nothing to do with this. I did take the custom entity thing from the hammer script. I don't really know what cause the issue, solarus 1.4.5 didn't solved it
I'm gonna work-around with metatable, this might be the issue (since the collision need to check if it is a pickable) but I don't know how i'm gonna do it ...