sens = cont.sensors[‘Message’]
own[‘target’]=sens.sender
it will make my life much easier, I can set the message subject to X, and have the message be own.name but that is 2x more python… as it seems this would already be set up
and then you should be able to just assign to the body of the message any string you want:
messageAct.body = cont.owner.name
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:
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
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
So no huge logic spike, just a ,02 ms increase for about 1 frame
But it is annoying to generate errors at all
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)
message
title -> “hello” >> string
message -> “…” >> string
sender : object >> gameObject (or None)
other things : [] list