Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbtn clarification #2

Closed
HomineLudens opened this issue Jan 6, 2017 · 7 comments
Closed

pbtn clarification #2

HomineLudens opened this issue Jan 6, 2017 · 7 comments
Assignees
Milestone

Comments

@HomineLudens
Copy link
Collaborator

Not sure if pbtn is working as it should. If I keep pressed a key pbtn return true every odd frame.
I was expecting to only receive true again after releasing and pressing again the button.
Try in Win10 64Bit with 0.0.13 and 0.0.12

@nesbox nesbox added the question label Jan 6, 2017
@nesbox
Copy link
Owner

nesbox commented Jan 6, 2017

pbtn returns true if button wasn't pressed last tick
also returns true on every 6 ticks if you pressed it more than 30 ticks
it designed to use it with menus or items select (like in pico8)

@HomineLudens
Copy link
Collaborator Author

Could be possible to add a sign to the method to make it works as a single shot trigger? Something like pbtn(0,1)?
Is the wiki here editable to add some documentation?

@nesbox
Copy link
Owner

nesbox commented Jan 6, 2017

Not sure if we need make api more complicated in this case, so you can use code like that

local last=0
function btnp(index)
	return btn(index) and (last&(1<<index)==0)
end
function TIC()
	if btnp(4) then 
		trace("pressed A")
	end
	last=btn()
end

PS.
Unfortunately I found ugly bug in TIC integration with Lua and the code above will work only in 0.0.14 😕

@nesbox nesbox added the bug label Jan 6, 2017
@nesbox nesbox added this to the 0.0.14 milestone Jan 6, 2017
@nesbox nesbox self-assigned this Jan 6, 2017
@HomineLudens
Copy link
Collaborator Author

Thanks for the nice snippet. I wrote a similar workaround in Tic Tac Toe demo, but have this in the API would make the code looks cleaner.

@nesbox
Copy link
Owner

nesbox commented Jan 7, 2017

Ok, can do something like that
btnp [ id [ hold period ] ] -> pressed
it will return true every period ticks if button is held for hold ticks
by default btnp(id) will work like "single shot trigger"

@HomineLudens
Copy link
Collaborator Author

That will fit really well in the API and will cover most of common needs.

@nesbox
Copy link
Owner

nesbox commented Jan 12, 2017

fixed in 0.0.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants