get message subject with python

Hello,

I’ve a little problem with messages.
To send a message seems to work fine on that way:

mes = cont.actuators[‘mes’]
mes.subject = own[‘item’]
cont.activate(mes)

but i don’t get it how i can get the subject now on the sensor. I wanna add a new object to the scene with

add = cont.actuators[‘add’]
add.object = a
cont.activate(add)

my thoughts are that i get the subject wich is the item property from the other object as a. there is existing an object wich is named like this property value so that it automatically add the object wich is named like the property of the sending object. But how do i tell a to be the subject of the recived message?
i tried the following but that dosn’t work.

mes = cont.sensors[‘mes’]
a = mes.subject

Can anyone help me out? Or maybe any other idea how i can add this objects? it’s my first try at BGE and python.
And sorry for my bad english ^^

–inken

hi inken,

Are you trying to retrieve the subject the Message sensor is looking for or are you trying to retrieve the message that was sent by the Message actuator to the Message sensor?

If you are trying to retrieve the message that was sent, use the bodies variable.

# get controller
controller = GameLogic.getCurrentController()

# get message sensor attached to the controller named message
messSensor = controller.sensors["message"]

# get list of message bodies
list = messSensor.bodies 

Here’s a link to the python code KX_MessageSensor variable bodies

Clark

Thank you Clark, it works fine with the bodies.

I get a property value as val and del tell the message actuator to set his subjectwith

act.subject = val

but it doesn’t funcion, he’s asking for a string but it shouldn’t be so.

No idea for this?