In a recent post I had a problem implementing a delay in the proximity manager and Jeff has suggested the solution of using "vizproximity.waitEnter" and a while loop:
Code:
def proximityTask():
global handstate
while True:
yield vizproximity.waitEnter(SensorIndexFinger)
print 'entered sensor'
yield viztask.waitTime(2)
print 'two seconds elapsed'
handstate = 1
viztask.schedule(proximityTask())
However, with this code I have a new problem and I decided to open up a new thread:
What happens now is that, once the sensor is entered, the action (change of the variable handstate from 0 to 1), will be delayed by two seconds. However if I happen to enter the sensor again very quickly, before these two 2 seconds have elapsed, nothing happens, as it seems that it is not registered that the sensor has been entered, until the first action takes place.
I wonder if there is a way around this? I tried to to the following: I will change a new variable upon entry but then I will make a new function where I say that IF the new variable "condition" is equal to 1 then after 2 seconds the handstate should change to 1 (= delayed action). This way I am hoping that I am not delaying the action itself in the proximity manager, I am delaying it outside of that function so that the proximity manager can freely register all entries.
Code:
def EnterProximity_IndexFinger(e): # decide what happens on sensor entry
global handstate, condition
e.sensor == SensorIndexFinger
condition = 1
print condition
manager.onEnter(SensorIndexFinger,EnterProximity_IndexFinger)
with this I am just changing the variable condition and the I will try to use that in the following way:
Code:
def Handdelay():
global handstate, condition
print "now"
if condition == 1:
#yield vizproximity.waitEnter(SensorIndexFinger)
yield viztask.waitTime(2)
handstate = 1
print "open hand"
else:
handstate = 0
viztask.schedule(Handdelay())
Unfortunately, the condition change is registered as soon as I enter the sensor, but the function which is supposed to call the delayed action (handstate changing to 1) is not working.
I would be very grateful for help!