Using monarch.is_visible() to send message fails

Using Monarch I haven’t yet come up with a good way to send messages to the various screens. Gameanalytics keep reporting errors like this:

ERROR:SCRIPT: /main/main.gui_script:40: Could not send message 'test' from 'main:/main#main' to 'test:/test#test'.
stack traceback:
  [C]:-1: in function post
  /main/main.gui_script:40: in function </main/main.gui_script:37>

I’ve tried using monarch.is_visible() to check whether the screen is available to send messages to, but this doesn’t always work. See an example project: MessageSending.zip (4.8 KB)

One solution I have found that consistently works is for each screen to register init() and final() to a custom module. Is this the best option to make sure the error above is not reported when using Monarch?

I think the problem here is that is_visible() will return true up until when the screen is unloaded. And if you send a message on the same frame as the proxy is unloaded you get the error seen above. Maybe combine your check with is_busy()?

if monarch.is_visible("test") and not monarch.is_busy() then
end
2 Likes

That combo actually works, nice one! Thanks @britzl.