This is likely a dumb question, but I have a for loop that is structured like so:
def sw_trough4_inactive(self, sw):
for i in range(self.game.timer.position, 40):
starttime = time.time()
print "Timer position %s" % self.game.timer.position
time.sleep(3.0 - ((time.time() - starttime) % 3.0))
This works beautifully and will tilt my machine after the 40th step of my fictional timer unit (which is what I want). Unfortunately, I have to wait for the full movement of the timer unit to the 40th position until I can press other switches!
What is the preferred way to allow for switch input to still take place while the game is executing a time-delayed for loop? Of course, if I don't have the 3 second delay that the game provides mechanically in the real world, the loop executes so quickly that I don't notice it practically, but since I am waiting for the user to press either the start button or the coin switch, I can't really just eat their money or sit there blankly. ;-) I guess I need to push my actual loop to a thread? I understand how python threading works, at least conceptually, and the concept of the GIL. Again, this is a really simple basic question and I feel dumb for asking it.
I absolutely know I am missing something really silly, and I just can't think of why this wouldn't be working.
I have a similar trouble with while loops, so much so that I threw out all the code I had previously written that used whiles and am now rewriting them with sw_x_active() type calls instead. This seems to work (except in the above case), but in separate modes, when entering into the mode, my sw_switch_inactive() methods are not being called. If I manually actuate the switch so that it changes state from closed back to open, it will allow the method to fire, but if I enter the mode, it will not fire the method.
In this case, I've written a 'tilt' mode, which will do a few different things.
1) Step the timer unit until the machine tilts.
2) Handle the tilt ring activation, eventually rendering the appropriate layer.
3) Wait for a coin (uses a method that relies on switch replay0 being active) - defined as sw_replay0_active()
4) Wait for a start button press (uses a method that relies on switch replay0 being inactive) - defined as sw_replay0_inactive()
I have print statements in #3 and #4, and they are not printed unless I bounce the switch. Once the mode comes online, I would expect that one or the other would fire and print something. They don't.