Hi,
Messages can be an important part of your game. They are quite easy to use but they have their issues as well.
What are the benefits of messages?
-
easy to setup
-
flexibel to use
[LIST] -
no need to worry if there is an recipient and how many
-
no need to worry who send a message from where
-
no need to worry inter-scene communication
-
can be filtered by subject
-
it is save - messages do not get lost e.g. after scene change or when multiple messages are received
-
up-to-date - messages lives for one frame only (no queuing of outdated messages)
[/LIST]
But there are also some disadvantages: -
can transfer strings only
-
relatively slow (when used in 1:1 communication) compared to property copy
-
multiple messages can be received at once - which might require Python code
-
it is possible to send the value of a proberty - but not to save it in another property via logic bricks.
-
difficult to track what messages are in the queues
-
it is not possible to save messages in a save/load system
What information can a message carry?
- String - Iit might be difficult to evaluate the string (Python controller needed)
- True/False - True = message received / False = no message
[LIST] - can be used to trigger specific tasks (e.g. a Python controller)
- can be used for simple counters
- can be used to synchronize multiple independent objects
[/LIST]
When to use messages?
- when the recipient is not known - or we do not care
[LIST] - example: send the health of the player
[LIST] - there can be one or more GUI elements listen
- there can be a game flow elements listen (for respawn)
[/LIST]
-
when the sender is not know - or we do not care
-
example: collecting coins
[LIST] -
each coin is sending a message when collected
-
a counter object is counting the received messages
[/LIST]
-
when the sender and the recipient are in different scenes.
-
to carry temporary information over to the next frame (e.g. on scene switching)
-
example: you can send a message “game continues” - scenes from a newly started game wouldn’t get such a message
-
when it is important to catch every message
-
when copying properties the previous value is overwritten (no history)
-
when using messages all messages are available and can be used to produce the desired results
[/LIST]
When is it better not to use messages?
- when it is a 1:1 communication with known participants (better use property copy)
- when to much messages are floating around
- when complex data should be transferred
- when you need Python code already (and you know the recipients)
Any ideas to improve the use of messages?
- Write down what messages are send and what purpose they have (you can use a text block for this documentation). If you use Python code to send messages such socumentation is a MUST DO. Otherwise no one knows where this messages are coming from.
- Use subject filters
- Message sensors should always have True Pulse on.
I hope I did not forget something.
Monster