Get message python - Solved! Thanks -[killer]-

Hey all,

Does anyone know how to recieve a message in python without having to add a Sensor or 1 Sensor for more messages for it? I use this to send:

GameLogic.sendMessage(“Subject”, “Body”, “Object”, “Object”)

Thanks. ^^

Why on earth are you sending messages? Personally I think that’s one of the more unclean methods of sending variables from one object to another (or trigger events) a BOOL property is much more clean.

That said I don’t believe it’s possible. Just had a gander in the API and didn’t see anything about it. Best bet would be to either add a message sensor or use BOOL properties (then instead of another sensor you would just do: object[‘variable’] == TRUE: to add events

Uhm, I would like to use the easiest way but im pretty newby in python. xD Can you explain me how to use bools for this?

Ok, your main object would have a property that is a BOOL called… umm… boolProp set it to either true or false. Then in your python script use:

if own[‘boolProp’] == TRUE:
handle my event

you change change own to another object using:

sc = GameLogic.getCurrentScene()
obl = sc.objects

and then use: obl[‘OBmyobject’] to get objects. So if your main char is a cube (and defined as own in your python script) and you wanna set the prop on a sphere called SphereCharacter in blender use:

sc = GameLogic.getCurrentScene()
obl = sc.objects
sphere = obl[‘OBSphereCharacter’]
if sphere[‘theSphereBoolProp’] == TRUE:
then handle your event

you can also change the value using:

sphere[‘theSphereBoolProp’] = FALSE

if this doesn’t make sense I can make a blend file, but I think I was fairly descriptive :slight_smile:

NOTE: I did not test any of these lines, although I’m extremely confident in my skills, there may be a typo somewhere.

Works perfect man. Thanks for teaching me this and your perfect explanation. ^^
I’m really thankful. =D

1 Like

Wow, glad I could help :smiley:

Keep blending man :slight_smile:

1 Like

So killer i think thats a good way but i’m using send message because i am communicating through three layers of overlayed scenes. is there anyway i can ditch messages?

Messages are good:

  • if you want to spread information out to objects without to care who they are, how many and if they even exist. Something like a “news letter”.
  • if the receiver does not care who send the message

I wrote a postregarding messages. It includes an example how to extract all messages of a sensor. Two answer gamemasters question:

  • You need at least on message sensor.

This makes sensor because, the sensor triggers the script controller.

1 Like