Message sent but not received (SOLVED)

Hey all, sorry if this has cropped up somewhere but I haven’t found anything browsing the forums yet. I’m trying to send messages from one script to another so that I can have a health bar locked to the camera rather than the character. The code around the msg.post() calls is definitely running. I’m not getting any errors and it isn’t showing anything about not being able to find the message recipient. However, the on_message function in question isn’t being called.

Thanks in advance. Let me know if there’s any other information that might be relavent.

Welcome @AngryScot! :wave:

The problem is that you specified the on_message function local. Remove the local before function on_message(...) and it will work :wink:

on_message is a special function used by Defold in lifetime cycle: https://defold.com/manuals/application-lifecycle/
By typing local function with the same name you just declared a function that is not called anywhere (you never ever get a message “message received:…”, because the function wasn’t called).

For future: Always verify, if the address is correct, e.g. print("My address is:", msg.url()) in a camera script’s init function. If everything is correct, you can remove that print :slight_smile: If you are messaging between two objects in the same collection you can address them by only path and fragment :wink:

Please, if it is possible, paste the code in the forum instead of screenshots next time (there is </> button above so you can format some part of the post as a code :wink: )

3 Likes

Thanks for the quick response! I figured there must be away to put in the code but wasn’t sure which button to use and figured someone would correct me.

1 Like

No problem, just trying to help :wink: It is always easier to just paste the code and see what is going on, but in that case I suspected that local word at the first glance, so just needed to check it :wink: Is it working now? If so, you can also add “(SOLVED)” at the end of the topic :smiley:

Yep, that was the problem! Thanks again.

1 Like