local function on_answer_button_callback(self)
msg.post("answer:/screen#gui", "answered", { answer_explanation = "ANSWER!" })
end
and in answer.gui_script
function on_message(self, message_id, message, sender)
monarch.on_message(message_id, message, sender)
self.druid:on_message(message_id, message, sender)
if message_id == hash("answered") then
local _answer_explanation = message.answer_explanation
local answer_explanation_text_node = gui.get_node("answer_explanation_text")
gui.set_text(answer_explanation_text_node, _answer_explanation)
print("Received answer_explanation:", _answer_explanation)
end
end
Problem is, message is not passed from one script to another ie. quiz.gui_script to answer.gui_script. Always get error message: Could not send message ‘answered’ from ‘quiz:/quiz#screen’ to ‘answer:/screen#gui’.
IDs for collections are correct - “quiz” and “answer” with “screen” game object with “gui” in both colelctions
Maybe, still learning Defold. Which function should be used for load delay? This is whole button callback:
local function on_answer_button_callback(self, button_instance)
local button_data = button_instance:get_data()
if button_data then
if button_data.is_correct then
print("CORRECT ANSWER!")
button_instance:set_answer_texture(true)
monarch.show(hash("answer"))
else
print("INCORRECT ANSWER.")
button_instance:set_answer_texture(false)
for i, answer_button in ipairs(self.answer_buttons) do
local abtn_data = answer_button:get_data()
if abtn_data.is_correct then
print("--- SHOW CORRECT ANSWER --")
answer_button:set_answer_texture(true)
monarch.show(hash("answer"))
end
end
end
-- disable answers after user click
for i, answer_button in ipairs(self.answer_buttons) do
answer_button:set_enabled(false)
end
msg.post("answer:/screen#gui", hash("answered"), { answer_explanation = "--SAMPLE DATA--" })
end
end
Tnx both, yes, it was async problem. Screen didnt load fully to apply text. Using msg.post in monarch.show function parameter also didnt performed as expected, loading (applying) text after 1 second delay, showing visible old text on screen for a second. However, using monarch.show and setting data within parameter and accessing it in another gui script after screen was fully loaded, with monarch.data function worked perfectly.