3
0
mirror of https://github.com/britzl/monarch.git synced 2025-06-27 10:27:49 +02:00

monarch.post() requires monarch.on_post()

This commit is contained in:
Björn Ritzl 2023-08-03 08:35:04 +02:00
parent df2a2a62ea
commit 5d8fa8e220
2 changed files with 5 additions and 11 deletions

View File

@ -177,7 +177,7 @@ Remove a previously added listener.
## monarch.post(screen_id, message_id, [message]) ## monarch.post(screen_id, message_id, [message])
Post a message to a visible screen. If the screen is created through a collection proxy it must have specified a receiver url. If the screen is created through a collection factory the function will post the message to all game objects within the collection. Post a message to a visible screen. The screen must have set a message listener using `monarch.on_post()`.
**PARAMETERS** **PARAMETERS**
* `screen_id` (string|hash) - Id of the screen to post message to * `screen_id` (string|hash) - Id of the screen to post message to

View File

@ -1173,17 +1173,11 @@ function M.post(id, message_id, message)
assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id))) assert(screens[id], ("There is no screen registered with id %s"):format(tostring(id)))
local screen = screens[id] local screen = screens[id]
if screen.proxy then if screen.receiver_url then
if screen.receiver_url then log("post() sending message to", screen.receiver_url)
log("post() sending message to", screen.receiver_url) msg.post(screen.receiver_url, message_id, message)
msg.post(screen.receiver_url, message_id, message)
else
return false, "Unable to post message since screen has no receiver url specified"
end
else else
for id,instance in pairs(screen.factory_ids) do return false, "Unable to post message since screen has no receiver url specified. Set one using monarch.on_post()."
msg.post(instance, message_id, message)
end
end end
return true return true
end end