About Store Forum Documentation Contact
Donations:
140$/mo



Post Reply 
Kb.eat() usage
Author Message
Dwight Offline
Silver Supporter

Post: #1
Kb.eat() usage
Hi there,

From what I understood from the header is that the eat() method can be used to "disable" keyboard usage in other functionality: it should disable, for example, the movement keys from my character as 'it's a different code'.

Code:
virtual void update(C GuiPC &gpc)
   {
      super.update(gpc);

      if(Gui.kb()==this)
      {
         if(Kb.bp(KB_ENTER))
         {
            Kb.eat(KB_ENTER);
            Str t=T();
                t.clip(pnconstants::MaxChatLength);
            if(t != "" || t != " ")
            {
               Chat.New(ChrData.name+": "+t);
               ClientSendChat(Server, t); hide();
            }
            
         }
      }else
      {
         hide();
         if(Kb.bp(KB_ENTER))
         {
            Kb.eat(KB_ENTER); clear().activate();
         }
      }
   }

However, it doesn't seem to work no matter where I place it. Did I perhaps misunderstand the header information? How can I disable other functionality by keyboard input as soon as the TextLine is being used to type a message?
04-14-2021 11:12 PM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Bronze Supporter

Post: #2
RE: Kb.eat() usage
I believe that Kb eat is only for the one update loop, so be weary of where the kb eat is called as anything on that update loop before will still be able to use it and the next update it will be free to be called again
04-14-2021 11:52 PM
Find all posts by this user Quote this message in a reply
Dwight Offline
Silver Supporter

Post: #3
RE: Kb.eat() usage
Then a workaround would be to create a boolean that will disable user input in the player update function where keystrokes are checked if any textline is active. Easy to do, but I still wonder how we would use eat() in this case.... just curious grin
04-15-2021 10:02 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Kb.eat() usage
Kb.eat will only clear pushed released Kb.bp and Kb.rs etc states. But it does not clear Kb.b state.
But for continuous movement you should better check that when processing the character movement.
Example:
If(!Gui.kb() || Gui.kb().type()!=GO_TEXTLINE)processCharacterMovement();
That's a simple example
04-15-2021 01:19 PM
Find all posts by this user Quote this message in a reply
Dwight Offline
Silver Supporter

Post: #5
RE: Kb.eat() usage
That deffinitely helps in understanding what kb eat does! The example you provided I implemented and all works as it should right now smile

Thanks for explanation, Greg!
04-15-2021 05:07 PM
Find all posts by this user Quote this message in a reply
Post Reply