Giter Club home page Giter Club logo

Comments (7)

nesbox avatar nesbox commented on May 16, 2024

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)

from tic-80.

HomineLudens avatar HomineLudens commented on May 16, 2024

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?

from tic-80.

nesbox avatar nesbox commented on May 16, 2024

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 😕

from tic-80.

HomineLudens avatar HomineLudens commented on May 16, 2024

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.

from tic-80.

nesbox avatar nesbox commented on May 16, 2024

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"

from tic-80.

HomineLudens avatar HomineLudens commented on May 16, 2024

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

from tic-80.

nesbox avatar nesbox commented on May 16, 2024

fixed in 0.0.14

from tic-80.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.