Log In  


I've run into a problem where nested menus are reading the same btnp input and I was wondering: is there a simple way to clear or ignore all the input until the next frame?

There is probably a different way to do it, but my code is kafkaesque and has gotten progressively worse as I've tried to solve this problem, so I felt it in poor taste to subject you to that.



On a related note, it would be nice to have an option to btnp that doesn't do auto-repeat when you hold it down. I had to code my own wrapper around btn to make double-jump work reasonably in my game.


1

At the top of your code, do something like this:

function new_input()
  return {
   [0]=btnp(0),
   [1]=btnp(1),
   [2]=btnp(2),
   [3]=btnp(3),
   clear = function (self, which)
    self[which]= false
   end
 }
end

Then at the top of _update, do something like this:

local in = new_in()

Now you can replace tests of btnp(0) inside _update with in[0], and you can also do in:clear(0) if and when you decide to clear it.

Of course, if your _update calls another function, it will have to pass "in" to that function - can't call new_in twice in the same frame without introducing exactly the problem you're hitting.


Thanks! I'll give that a shot.


Worked great with a couple modifications, thanks for your help Johnicholas. ❤



[Please log in to post a comment]