Comments (7)
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.
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.
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.
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.
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.
That will fit really well in the API and will cover most of common needs.
from tic-80.
fixed in 0.0.14
from tic-80.
Related Issues (20)
- [enhancement] inform languages versions (lua, js, etc) in "help version" command HOT 2
- Final horizontal scrolling correction.
- [request enhancement] mouse button events HOT 3
- imported code adds a trailing space in all lines
- [flatpak]: save to XDG_DOCUMENTS_DIR
- [flatpak]: pro version
- GameShell: Cannot launch version 1.1.2837 Pro (be42d6f) HOT 1
- [idea] virtual files (or tabs) inside cartridges.. for organize libs, classes, etc HOT 2
- [website] redisign the "play" section
- [website] Creation of a new website by the community HOT 12
- Slow Tic80 is back. HOT 5
- tic80 doesn't find my required lua files HOT 10
- Problem while making new binding, demo example not loading HOT 2
- [idea] optional serial/telnet console for debugging HOT 1
- Can't add credentials in code editor. HOT 3
- Raspberry Pi TIC-80 not connecting to network HOT 1
- JavaScript: Update to QuickJS-NG
- load command behaves oddly around the website HOT 1
- Report cart to remove from tic80.com
- Music editor bug: note preview mute uses wrong channel
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tic-80.