disabling keys

keys is needed to move a player, but sometimes keys can spoil the game, for example, if you are seeing an interval animation that cannot be interrupted, controlls must be disabled,

imagine a player jumping, to jump, you press a button, but when you are jumping the jump button must be disabled because if not, your player will jump infinities times while you press again…

other case: when your player lost, typically game will reproduce an animation (maybe player go out the screen crying), in the process of loosing and reproducing that animation, keys must be disabled, because if not, if we press movement or jump keys, the player will returnt to the scenery instantly haha :laughing: that is inconsistent.

Do I must to create a variable ?, or there is a method to disable the controlls,?, haa forgot to tell you, i tried with a variable, but the system reads the script so fast and instantly, that disable variable is ON and then OFF rapidly… :confused:

thank you…

yes

I’m not the coder for our team, but we use both a timer and a disable veriable for our keys.

     if (self.keyMap["menu"]!=0):
          #This is to see if it can be called out not. Theres is a timer so theres a little time in between calls.
          if self.CanWork == True:
            if task.time >= self.CommandWait + .25:
              self.CanWork = False
              self.UserHasMouse = True
              self.tempchatonoff = 1
              self.GameMenu()
          else:
            self.CommandWait = task.time
            self.CanWork = True
      #Theses are the key commands for moving around. For default we use the W,A,S,D keys.
      #Left = D, Right = A, Forward = W, Backword = S
      if (self.keyMap["left"]!=0 and self.tempchatonoff !=1):
          base.camera.setX(base.camera, - (self.elapsed*25))
          base.camera.setZ(base.camera, + (self.elapsed*2))
      if (self.keyMap["right"]!=0 and self.tempchatonoff !=1):
          base.camera.setX(base.camera, + (self.elapsed*25))
          base.camera.setZ(base.camera, + (self.elapsed*2))
      if (self.keyMap["forward"]!=0 and self.tempchatonoff !=1):
          base.camera.setY(base.camera, + (self.elapsed*25))
          base.camera.setZ(base.camera, + (self.elapsed*2))
      if (self.keyMap["back"]!=0 and self.tempchatonoff !=1):
          base.camera.setY(base.camera, - (self.elapsed*25))
          base.camera.setZ(base.camera, + (self.elapsed*2))

nice !, going to study the code… and variables
thanks both.

If you use polling and input loop, do it by adding/removing the loop to/from task manager.

If you use events, you can filter which events should be processed at a time. Kind of event mask, the implementation is via button thrower’s prefix.

base.buttonThrowers[0].node().setPrefix(string)

now have both methos to study… will try too thanks