Shoot the messenger? (Problem with messages)

Hi all

I thought I had this licked, but I have found a strange problem with my script:

There are two boxes (addbuttonL and addbuttonR) that when left clicked add an object at an empties position (P1 and P2, underneath the buttons). If one is clicked the corresponding ship is spawned at that position.

But if I try to spawn the other ship once the first is spawned I get nothing, even though it will spawn normally on its own.

Can anyone see my mistake?

Cheers

Paul

Attachments

MessageProblem.blend (99.2 KB)

Include the cont, scene, and owner variables inside the Create() function.

Ah! Thank you, Riyuzakisan!

When you define variables at the global/module level (top of the script where you would import stuff), they are defined once and not updated the next time a sensor activates the Python Module controller. If you want to test this out, you can put “print(‘some message’)” under the import code and run the game. You’ll see that it only prints the message once.

If you use this as your code:


import bge
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
owner = cont.owner


PpositionName = "positionName"
       
def Create():
    
    sensor0 = cont.sensors["Main"]
    print(sensor0.owner)

It will print only the name of the owner of the first message sensor to be activated, even if you click on the other button to trigger the opposing message sensor.

Cool, thanks for the explanation- it makes things much clearer.