So I’m reading Collision messages in Defold and am trying to implement it.
Inside of the script of the same game object that has the collision:
function on_message(self, message_id, message, sender)
if message_id ==hash("is_book_in_slot") then
if message_id == hash("trigger_response") and message.other_id == hash("/book_slot_go#book_slot_collision_object") then
msg.post("/minigame_go#shelving", "shelved_book_in_correct_slot")
else
msg.post("/minigame_go#shelving", "shelved_book_didn't_slot_in")
end
end
end
The script that send messages to it and is part of minigame_go:
function init(self)
msg.post(".", "acquire_input_focus")
go.animate("/book_going_into_slot_go", "position.x", go.PLAYBACK_LOOP_PINGPONG, 600, 1, 2)
timer.delay(8, false, function()
print("Failed.")
msg.post("main:/main#main", "game_over")
end)
end
function final(self)
end
function on_input(self, action_id, action)
if action_id == hash("space") then
msg.post("/book_going_into_slot_go#book_going_into_slot", "is_book_in_slot")
end
end
function on_message(self, message_id, message, sender)
if message_id == hash("shelved_book_in_correct_slot") then
print("Success.")
msg.post("main:/main#main", "game_over")
elseif message_id==hash("shelved_book_didn't_slot_in") then
print("Failed.")
msg.post("main:/main#main", "game_over")
end
end
I’m confused, from reading the documentation, I would’ve thought that since my book and slot collision objects are both triggers, it should register a trigger response, and I think I got the message id correct? Thanks in advance.