Beginner coding....

Sorry for the stupid question, but i am just getting into arduino coding and have got some basic help from some internet search and youtube videos. I am looking to produce a basic automotive transmission controller based on an arduino uno board. I need to control two 12v solenoids back and forth, on and off in different sequences to shift the transmission using paddle shifter pins. I have a basic code to turn on and off the solenoids, but im looking to prevent the upshift button from being pressed more than"x" amount of times and not allow more than that.

Then press another button to downshift the solenoids in a reverse function back the other way. But i would need to stop the buttons from forcing the solenoids from going past a certain amount of press functions.

Basically, press the button 3 times up, stop even if the up button is continuously pressed, then back down to 1, and stop, even if the down button is pressed repeatedly....where do i begin. Cant seem to find any info on how to stop the button function if over pressed. Thanks for any help i can get.

Use a variable to count the up/down shifts. Increment it when moving up. Decrement it when moving down. Test whether it is at either limit before incrementing or decrementing and if so do not change the value.