key time

i found this piece of code in the manual and i have a few questions about it:

class ReadKeys(DirectObject.DirectObject):
  def __init__(self):
    self.accept('time-a-repeat', self.printRepeat)

  def printRepeat(self,a):
        print "repeat a",a

i tried it and am i correct that it gives the global time it was pressed?
and i see that the function needs the “self” argument and the “a” argument.
am i correct in assuming that a holds the time?
and what if i have a system like this:

def turn(self, buttons):
    if buttons == "a":
        turn left
   elif buttos == "d"
        turn right

would i need to have both keys as arguments?

def turn(self,a,d):

or is there another way?

thanks in advance,


No - you’ll need to create different functions to turn right and left.

Yes, on “time-” event the corresponding time is sent to the self.printRepeat function. So, “a” in the definition of self.printRepeat() is actually the time when the event was sent (I not sure what time exactly, maybe David knows). Also, I don’t really understand why you want “time-” events when creating movements…

There are many ways to define player movements. Make sure you study Roaming Ralph sample (and there are numerous other ways in the forum, that use either keypolling or event system).