1

I have a problem in that I want to go (via increments of 0.01) from 0 to 1 (that bit is easy) if an external condition (which is being evulated automatically) is false and stop the counter if the condition is true.

The condition is if a collision has occured between two objects. I know this part works correctly since I have tested it manually and within a loop. But stopping the counter if a collision has occured is proving tricky. I'm sure it is something very very simple that I'm missing out.

   def autoHandClose():
   global collisionDeteched # this is set to false but on collision correctly changes to true
   counter = 0 
   for x in range(100):
     if collisionDeteched == False:
        counter = counter + 0.01
        h.setGesture(hand.GESTURE_FIST, closeThumb=True, weight = counter)
     else:
      break

The weight parameter is from 0 to 1 (hence the reason why I want to go from 0 to 1 to close the hand) I can close the hand but can't get it to stop if a collision is detected. This method is assigned to a keyboard button press.

I'm guessing the logic is wrong, right?

1 Answer 1

1

Is the check for 'collisionDetected' running on a parallel thread to this loop? If not you will never exit the loop since the value of collisionDetected will never be updated. Is this the case?

Also on a side note:

You might want to change your for loop to look a little more something like this to make your code cleaner:

for counter in range(0,1,0.01):
   ...

This will reduce the need to set counter in your loop.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the reply, the check for 'collisionDetected' hasn't thrown up any problems when using a slider to change the value of of counter. I'll double check. I don't know if I have my logic nested incorrectly too.
Does the value for collisonDetected ever get updated during the for loop though?
Yes it does. Its only when I add the if statements to interupt the for loop does it not work.
Try removing the interrupt statements and instead output collisionDetected at each step in the loop. Then you can see if it ever changes before the loop terminates or after.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.