L4 HW Beginner inhibitor

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
emily
Posts: 22
Joined: November 9th, 2019, 9:04 pm
Location: Kentucky

L4 HW Beginner inhibitor

Post by emily » November 15th, 2019, 12:53 am

Hi everyone, could you say more than the inhibitor. I seem to be missing something here. If a key is pressed and the inhibitor is defaulted to false the recticle slows down, but if it set to true nothing happens. What makes the inhibitor change to true? I seem to be hung up on this before I can move on.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: L4 HW Beginner inhibitor

Post by albinopapa » November 15th, 2019, 4:04 am

When you press a key on the keyboard, it will usually last a few frames, so the idea is to inhibit that press on subsequent frames until you release the key that triggered the inhibitor.

Code: Select all

if( a_is_pressed )
{
     if( ihibit_a == false )
     {
          // If we enter here, it means we haven't pressed the 'A' key yet
          inhibit_a = true;  // Now on the next couple of frames, 
          // ...do something when 'A' is pressed
     }
}
else  // if 'a_is_pressed == false
{
     if( inhibit_a == true )
     {
          // 'A' has been released, so we can set 'inhibit_a' to false
          // to allow a follow up press
          inhibit_a = false;
     }
}
Do something:
key_is_pressed | inhibit_key
--------------------------------------
true | false -> key is pressed for first time, handle pressed events
false | true -> key is released after press, handle release events
true | true -> key is still pressed from previous frame, just ignore
false | false -> key hasn't been pressed yet or has already been released and handled
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
emily
Posts: 22
Joined: November 9th, 2019, 9:04 pm
Location: Kentucky

Re: L4 HW Beginner inhibitor

Post by emily » November 15th, 2019, 10:47 pm

ok got it. Thanks again for clearing it up for me.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: L4 HW Beginner inhibitor

Post by albinopapa » November 16th, 2019, 9:39 am

You're welcome.

I am never really sure if I'm giving to much or too little information. I usually go overboard.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply