sendMessage and MessageSensor->PythonController

Is it expected for a PythonController to be activated twice when a MessageSensor is activated via bge.logic.sendMessage?

If I do this:
bge.logic.sendMessage(“a_subject”, “a_body”)

My PythonController is activated once with body “a_body” and again with no body whatsoever. I’ve been checking the length of the message body to disregard the second undesired message.

Any ideas?

I would guess that you’re calling bge.logic.sendMessage(“a_subject”, “a_body”) twice.

If you’re triggering that code via a keyboard sensor, make sure that you’re doing this:

if sen_key.positive:
    bge.logic.sendMessage("a_subject", "a_body")

If you just call send message in the main body, then it would run once when you press the key, and once when you release it, because you’re getting a sensor pulse on each event.

So, having it under the “if sen_key.positive” conditional would help you avoid that.