How do message interrupts work under the hood?

I have objects in my game that send messages to eachother in the message_received section and I’m unsure how how this affects the game running. I’m concerned that when messages are posted in on_message this could disrupt the execution of the calling script.

When a message interrupt happens (on_message is triggered), does it run as a thread in parallel with the rest of the program? Is it called like a function? Does the rest of on_message execute before the receiving object acts on the message?

Since Lua isn’t thread safe, we must always interact with it on the main thread.
So, there is no other calling your script at the same time you are receiving a message.

When a message interrupt

To be clear, these are not interrupts. We simply send the messages at certain points during the update loop (basically before and after each component type update).

1 Like

So on_message will run to completion before the other on_message responds to the message?

Also, what happens when multiple collisions happen simultaneously?

Thanks.

So on_message will run to completion before the other on_message responds to the message?

Yes, only one function will be called at a time, on the Lua thread.

Also, what happens when multiple collisions happen simultaneously?

They’re not “simultaneous”, but just registered in some order from the physics engine.
The events reported, are sent to the message listener, one after another.

2 Likes

Very helpful, thank you!