Log In  

Hey, I'm trying to figure out why btnp(x) seems to be true for one frame after stat(31)=="x" is true in devkit mode, or if I'm doing something dumb.

Here's an example cart. Press X, and it will show display the number of the frame that it registered the devkit keypress and the X button press respectively. There seems to be one frame difference.

Cart [#zoyifizotu-0#] | Code | 2019-02-21 | No License | Embed

My actual usecase is this: I have a password input in a game where I want to record numerical input from the devkit keyboard, but I also want it to record the X button, which confirms the password. Unfortunately, the 8 key is mapped to the X button; when they're also recorded on different frames it becomes a little convoluted to separate the two.

P#62134 2019-02-21 18:58

Sorry to bump this, but I'm very interested in finding out whether I'm crazy, have done a stupid error, this is intended behavior, or a bug.

Maybe it has something to do with how the devkit keyboard buffers and refreshes input in stat(31)?

Note that this seems to be a problem both with btn() and btnp(), I just chose the latter for the example since it's easier to catch.

P#62356 2019-03-01 13:23 ( Edited 2019-03-01 13:24)

You're not crazy. But it might be the way you've written out the code. When I wrapped everything up in the init, update and draw functions it was now sometimes firing at the same time but sometimes it would still exhibit the delay.

P#62501 2019-03-04 03:34

Still seeing the same behavior with a gameloop.

function _init()
 poke(0x5f2d, 1)
 f=0
 fs={0,0}
end

function _update()
 if stat(30) and stat(31)=="x" then
  fs[1]=f
  c=10
 else
  c=2
 end

 if btnp(❎) then
  fs[2]=f
  c=10
 else
  c=2
 end

 f+=1
end

function _draw()
 cls()
 print("press x",64-(7*4)/2,64,7)

 print("x",0,0,c)
 print(fs[1],16,0,c)

 print("❎",0,8,c)
 print(fs[2],16,8,c)
end
P#62518 2019-03-04 09:17 ( Edited 2019-03-04 09:18)

[Please log in to post a comment]

About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-08-24 03:10 | 0.021s | 4194k | Q:29