Author Topic: Freezing/locking keyboard during specific event?  (Read 45 times)

Eyth

  • Newbie
  • *
  • Posts: 6
    • View Profile
Freezing/locking keyboard during specific event?
« on: June 14, 2018, 04:26:57 pm »
Hi there again  ;)

Today I have a quick question. Hope I can describe it the right way:
I made a custom item with animations and all of that, the hero can use with the "item_1" command key (x). Works - so far so good ^^
But when I press the key, while the animation of the item used is running - the animation stops and starts new. In further consequence errors occur obviously...

Is it possible to lock the keyboard input, til item:on_using is finished, or you may have another idea?
Thanks for your advises in advance  :)
« Last Edit: June 14, 2018, 04:28:55 pm by Eyth »

Max

  • Full Member
  • ***
  • Posts: 101
    • View Profile
Re: Freezing/locking keyboard during specific event?
« Reply #1 on: June 14, 2018, 04:39:11 pm »
I've tackled similar problems this way:

I create a variable, "using_item", for example. This should probably be a variable local to the item's script, set it to false when the item is created. For the item:on_using() event, or the on_key_pressed, start it with the condition of if using_item ~= true. Then set the variable using_item to true first thing, and once you're done using the item (after a timer, or on_item_finished or whatever) set using_item back to false.

I think I might have some of the events referred to improperly here, but does the idea make sense?

Eyth

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Freezing/locking keyboard during specific event?
« Reply #2 on: June 14, 2018, 05:09:12 pm »
Yes, makes sense. Didn't think of that ^^
I'll have to try, to see how it fits best.

Thanks for the fast reply  ;)

Diarandor

  • Hero Member
  • *****
  • Posts: 956
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Freezing/locking keyboard during specific event?
« Reply #3 on: June 14, 2018, 07:37:04 pm »
To do it in a clean way you'll need to modify the event on_command_pressed and do nothing if the item is being used. That will avoid annoying built-in stuff like the hero state and animations being restarted. As Max says, it is convenient to define item:is_being_used() (or item:can_be_used()) for all items.
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”