I am creating a Tetris/bejewled like game where enemies fall from the sky in endless waves and you must click on different types of enemies to eliminate them all. The types are as follows:
blue-eliminate all enemies on the same row
green-eliminate all enemies on the same column
purple-switch blue/green types
yellow-increase ammo recharge meter
I have used message actuators to trigger the desired enemy effects, witch usually seems to work, but not always. I think this has to do with blender not being able to send out multiple messages at once, but i am not sure. Could someone take a look at my project and see what i am doing wrong? I hate to post such a vague question, but i have been working on this problem for days to no avail and have a deadline for school approaching!
(PS this is my first experience coding and working with the BGE, so some of my code may not be written well, i apologize, and any feedback on other aspects of my “little darling” is much appreciated).
game_v15.blend (1.17 MB)
I had a look at your blend file. I think you did it very well to place the logic of different purpose into different states. But without deeper analysis I can’t see how this is working together.
So I answer your question without referring to your file:
- The BGE can send multiple messages in one frame.
- A message sensor can receive multiple messages in one frame.
There are some things you should keep in mind:
-> A sensor triggers the connected sensor without status change only when the according pulse mode is activated. In your situation: when “healthBar” receives two subsequent messages the message sensor will remain True but not trigger the controller and therefore not reactivate the property actuator (which deactivates after one from automatically). Solution: switch on True Pulse at the message sensor. (see: Sensors - A Word on Pulses, Actuators - a word on execution, BGE Guide to Messages).
-> the message sensor evaluates if at least one message was received. This means there can be more.In your situation, if “healthBar” receives more than one message at a single frame, the property actuator will still decrease the property just once. This is usually no big deal if you can safely assume there will be just one message to be received (e.g. because it is not possible to click on two objects at the same time). If you can’t assume this you need a Python controller to evaluate the received messages (see: BGE Guide to Messages).
A quick follow up question, in my game whenever a yellow block is destroyed the healthBar object’s MP value should increase. I have this set up with logic bricks where when the yellow block type is destroyed it sends a message directed specifically at healthBar. This works, but as monster pointed out above, it only works for a single instance (ie destroying multiple yellows at once will only increase MP once). I learned from monster above that python should be used when performing 1:1 interaction and receiving several messages at once, but I am not sure how to do this. Do both the sender and receiver need to send out/receive a python message using sendMessage (subject, body, to, from) like a regular sensor, or do i just need python to receive the message? Also, if I do need a python script to send out the message from the yellow enemys, how do i write a python script that can be applied to multiple objects?
(PS, as stated above I am new to coding, and I would appreciate it if you treated me like a complete know-nothing when replying)
Sens.bodies[x]= a list of all recieved messages ?
Open up the text editor, click templets, gamelogic simple, edit that.
Can you remove an entry from a message sensor .bodies() list?
Thanks! I was able to fix the problem using sens.bodies[x].