message sensor can't get name of sender?

why is sens.sender not set up?


message detected---------python

in python

sens = cont.sensors[‘Message’]

it will make my life much easier, I can set the message subject to X, and have the message be but that is 2x more python… as it seems this would already be set up

Why not just use the value of the the body property instead?

because logic can’t set body =

So I need python to configure the message, and to receive it, as “body” is not accessible by logic,

So ([subject = death][ =] (I’m bob I’m dying) - Deathmessage


if subject of message = death---------python

Im tod and I am hunting you and I make 100’s of annoying messages if you die
so please tell my when you die.

if sens.bodies[0]=own[‘target’]:

if it had sens.sender

I could just use python on one end,

I am pretty sure that having the sender attached to each message is just common sense,
that is why there is a return address on mail :smiley:

It could be handy in other instances I am sure,

like look at who sends me a message,
or look at the first person who messaged me, then the second then the third
(message based waypoint navigation)


LookOutNowItsReallyOnWheels(navmeshDriver) (2).blend (1.06 MB)

You can set the message body through python.
You just have to get the message actuator like so:

cont = logic.getCurrentController()
messageAct = cont.actuators["Message"]

and then you should be able to just assign to the body of the message any string you want:

messageAct.body =

Then to retrieve the body of the message you should be able to do something similar except accessing the body of the message through the message sensor instead:

cont = logic.getCurrentController()
messageSen = cont.sensor["Message"]
messageFrom = messageSen.body

EDIT: You would actually have to loop through the bodies or know the index of the bodies your looking for because the message sensor stores a list of bodies that its received: KX_NetworkMessageSensor.bodies

I did it already :smiley:

see the file?

the “Player” on death sends the message [subject: death] []

the “robot” hears the message and if the message = own[‘target’]:
own[‘target’] = “X”

so the robot forgets it’s target if it says “Im dead”

it could just be

message-----subject death------python if sens.sender =own.[‘target’]: own[‘target’]=“X”

If the player says’s I’m dead, then the robot can stop tracking the player based on what he’s currently tracking rather than who sent the message.

Indeed the information who is the sender of a message can be important (like an email).

Sending the name in the property is only valid if there is only one object with this name.

A different approach is following: the message notifies anyone in the scene that an object is dead (indicated by the subject). All objects interested, can check if the specific objects they are interested in (target) are still alive (e.g. by checking a property on the target). This should not be a big deal as long as they “remember” what the target is.

Have a look at the console you got some errors there, that might be important.

My code hunts (Name), kills(Name)and then throws exactly 2 errors (name is not on list!) before the message tells it to (Name is dead) stop targeting him :smiley:

So no huge logic spike, just a ,02 ms increase for about 1 frame

But it is annoying to generate errors at all :frowning:

How could I have it dying change all that are huntings own[‘target’]=“X”? without a message?

(this is filtered out from targeting)

if own[‘target’]!=“X”:
____Target =scene.objects[own[‘target’]
____Do stuff to target

is a bit strange that you cannot read the sender.
it should be an argument automatic , and can be just a gameObject or None (there some case where the sender can become invalid… it can be converted in None)

title -> “hello” >> string
message -> “…” >> string
sender : object >> gameObject (or None)
other things : [] list

comunications between different object is ever pretty convulted and prone to error.

anyway you can also use the property so send “messages” . (that is exactly convulted and prone to error :D)

own = cont.owner
robot= scene.objects[“robot”]
robot[“message”]=[“hello”, own]