Heeeeeelp sometimes it works sometimes it doesn't

Hi! i did a script to open and close a drawer, with one clic in any part of the drawer it opens and with the next clic it closes. It works but i can’t show this to my client because many times it doesn’t work.
I have the camera with an Always sensor and the drawer with a Mouse over sensor and a Left Button sensor, all linked to a python script .
The script is very simple:

c=GameLogic.getCurrentController()
o=c.getOwner()
sens = c.getSensor (“sens”) #Left Button
sens1=c.getSensor(“sens1”) #Mouse Over

#closed is an integer Property inicialized=0

if sens.isPositive() and sens1.isPositive and (o.closed==0)
o.setPosition([6.074, 3.721, 0.848])
o.closed=1
else
if sens.isPositive() and sens1.isPositive and (o.closed==1)
o.setPosition([6.074, 4.216, 0.848])
o.closed=0

It works but not always, sometimes i click the drawer and nothing happens, other times i have to click it 4 times for it to move, other times it moves but blinking, and so on.
So the user can’t trust on this, how can I improve this???

#this worked for me it, try it out :slight_smile:
from Rasterizer import showMouse
import GameLogic
cont=GameLogic.getCurrentController()
owner=cont.getOwner()
showMouse(1)

sen=cont.getSensor(‘sen’)
sen1=cont.getSensor(‘sen1’)

if sen.isPositive() and sen1.isPositive():
(tab)if owner.closed==0:
(double tab)owner.setPosition([1,0,0])
(double tab)owner.closed=1
(tab)else:
(double tab)owner.closed=0
(double tab)owner.setPosition([0,0,0])

#just put in your own positions

Thanks it’s working better, but can’t still show it to my client because, many times it opens and closes with only one click, it seems that it loses the closed variable value, i see it if i debug the varible and show it in the screen, sometimes it changes by itself (without any click) and so it opens and closes by itself.
Maybe because I inicialize the variable with cero at the Properties, when i define it, and maybe because of that but I don’t know how to fix it

Maybe the transparent texture has something to do with this?? when the object is painted with Vertex Paint this problem doesn’t almost happen, but when the object has an UV mapped transparent texture it happens almost every time

The first thing that I notice is you didn’t put the parentheses after sens1.isPositive, (either time.) The second thing I notice is that in the first if statement o.closed is changed to 1, so when it gets to the second if statement that one passes as well, change the second if to elif.

After looking at Demobobin’s script, I think it should work as well. (Both of you should use

 blocks so the tabs show up though.)