I would like to know the best way to change a value True->False->True->False, ect, using the same button to activate it. I tried a series of “if / else” statements, but the value jumps back and forth several times, depending on the button press length.
I am trying to ‘zoom in’ and ‘zoom out’ with the middle mouse button; changing the mouse sensitivity while zoomed in. I would post a .blend, but the file would be too unorganized and confusing.
Have the zoom animation carried out by an IPO property actuator (afaik, there is no easier way to determine the current state of object animation, and that’s what you want to determine what the mouse sensitivity value will be, because mouseclicks sometimes “go over” IPO actions, and the whole thing ends up out of sequence):
# Assuming your animation is 20 frames in lenght
# All properties are of type int, and are initially set to: zstate = 1, zoom = 0, frame = 1
# Make sure states don't keep changing when you hold down MMB
if middlemouse.isPositive() and own.zstate == 1:
own.zoom += 1
own.zstate = 0
if not middlemouse.isPositive():
own.zstate = 1
# When MMB is clicked again it will go back to zero, instead of two.
if own.zoom > 1:
own.zoom = 0
# Frame handler
if own.zoom == 1:
if own.frame < 20:
own.frame += 1
else:
if own.frame > 1:
own.frame -= 1
# Mouse sensitivity switch
if own.frame > 10:
# Change mouse sensitivity
else:
# Change it back to original
#Activate your zoom actuator/s:
GameLogic.addActiveActuator(zoom, 1)
Note: I just typed this up, so I didn’t test it, but it should work fine. Also I assumed you know how to do the whole cont and own thing and therefore set your own sensor + actuator assigments.
If there is anything you don’t understand, ask away.
You can also create a simple bool toggle switch without Python. In the Assign Property actuator, simply type !xxx (xxx being the name of your property) in the box where you would normally type the value to be assigned.
hhmm, I tried logic bricks before, but not with that extra skip property. The script works better in my case though, because I just placed it into my pre-existing mouse script.