my sensors are strange ?!

Hello,
I’m trying to make a simple user interface. Two buttons, Launch and Quit .
For each button a got a sensor mouse -> left button connected to one script where i am try to manage all sensors:

import bge

cont = bge.logic.getCurrentController()
own = cont.owner
    
quitter = cont.sensors['SensorQuitter']
lancer = cont.sensors['SensorLancer']

if quitter.positive :
    #bge.logic.endGame()
    print("Quitter")
       
if lancer.positive :
    print("lancer")
    

unfortunately nothing work at this time, and i don’t understand where i’m wrong .

Python script error - object 'Bouton quitter', controller 'And.002':
Traceback (most recent call last):
  File "menu.py", line 10, in <module>
KeyError: 'requested item "SensorLancer" does not exist'


If someone can help me :wink: , it’s will great.


Attachments


Is it me or are you not showing the complete code? Check line 10. Try Copying and Pasting the sensor name from the Logic Brick to Python
If that is the full code:

  1. Why is the text editor showing wrong lines?
  2. Maybe the console is finding the error in the wrong line.

Try connecting you menu.py script to an Always sensor.

Python script error - object ‘Bouton quitter’, controller ‘And.002’:Traceback (most recent call last):
File “menu.py”, line 10, in <module> KeyError: ‘requested item “SensorLancer” does not exist’

Look at the last line, it means you got no sensor with that name.
so rename your sensors.

Is it me or are you not showing the complete code?

it’s you

  1. Why is the text editor showing wrong lines?

where? all seems good to me.

  1. Maybe the console is finding the error in the wrong line.

No, in this case it is line 10 (and 9).

This one needs more info.
Connect both sensors (mouse over and mouse left click) to the script
for one button it will work, not for more.

simply because you got other sensors on the other button.
so it will not find both sensors and will give that error.

Also you need to check for the mouse over as well.
so change line 9 to Mouse.001

and the code to


#so you get if mouse over and left click is positive execute code.
if quitter.positive and lancer.positive:
    #action for 1 button here