Learn PICO8-LUA with Real Code Examples
Updated Nov 21, 2025
Code Sample Descriptions
1
Pico-8 Lua Button Press Counter
count = 0
function updateUI()
cls()
print("Button Count: "..count, 10, 10, 7)
end
function buttonPress()
count = count + 1
updateUI()
end
-- Simulate actions
updateUI()
buttonPress()
buttonPress()
Counts button presses and displays the current count on the screen.
2
Pico-8 Lua Color Toggle
isDark = false
function updateUI()
cls(isDark and 0 or 7)
print("Theme: "..(isDark and "Dark" or "Light"), 10, 10, 7)
end
function toggleTheme()
isDark = not isDark
updateUI()
end
-- Simulate actions
updateUI()
toggleTheme()
toggleTheme()
Toggles the background color between dark and light themes.
3
Pico-8 Lua Score Tracker
score = 0
function updateUI()
cls()
print("Score: "..score, 10, 10, 7)
end
function increment()
score = score + 10
updateUI()
end
function decrement()
score = score - 5
updateUI()
end
function reset()
score = 0
updateUI()
end
-- Simulate actions
updateUI()
increment()
decrement()
reset()
Tracks a player score with increment, decrement, and reset functions.
4
Pico-8 Lua Simple Timer
time = 0
function updateUI()
cls()
print("Time: "..time.." sec", 10, 10, 7)
end
function tick()
time = time + 1
updateUI()
end
-- Simulate actions
updateUI()
tick()
tick()
tick()
Counts seconds and displays the elapsed time.
5
Pico-8 Lua Health Bar
health = 100
function updateUI()
cls()
print("Health: "..health, 10, 10, 7)
end
function damage(amount)
health = health - amount
updateUI()
end
function heal(amount)
health = health + amount
updateUI()
end
-- Simulate actions
updateUI()
damage(20)
heal(10)
Displays a health value and updates it with damage and healing.
6
Pico-8 Lua Level Tracker
level = 1
function updateUI()
cls()
print("Level: "..level, 10, 10, 7)
end
function nextLevel()
level = level + 1
updateUI()
end
function resetLevel()
level = 1
updateUI()
end
-- Simulate actions
updateUI()
nextLevel()
nextLevel()
resetLevel()
Tracks the current game level with increment and reset.
7
Pico-8 Lua Coin Counter
coins = 0
function updateUI()
cls()
print("Coins: "..coins, 10, 10, 7)
end
function collectCoin()
coins = coins + 1
updateUI()
end
function loseCoin()
coins = coins - 1
updateUI()
end
-- Simulate actions
updateUI()
collectCoin()
collectCoin()
loseCoin()
Counts collected coins in a game.
8
Pico-8 Lua Power-Up Timer
powerTime = 10
function updateUI()
cls()
print("Power-Up Time: "..powerTime, 10, 10, 7)
end
function tick()
powerTime = powerTime - 1
updateUI()
end
function resetPower()
powerTime = 10
updateUI()
end
-- Simulate actions
updateUI()
tick()
tick()
resetPower()
Counts down power-up duration and resets.
9
Pico-8 Lua Ammo Counter
ammo = 10
function updateUI()
cls()
print("Ammo: "..ammo, 10, 10, 7)
end
function shoot()
ammo = ammo - 1
updateUI()
end
function reload()
ammo = 10
updateUI()
end
-- Simulate actions
updateUI()
shoot()
shoot()
reload()
Tracks ammo usage with reload and shoot actions.
10
Pico-8 Lua Star Collector
stars = 0
function updateUI()
cls()
print("Stars: "..stars, 10, 10, 7)
end
function collectStar()
stars = stars + 1
updateUI()
end
function loseStar()
stars = stars - 1
updateUI()
end
-- Simulate actions
updateUI()
collectStar()
collectStar()
loseStar()
Counts collected stars and shows progress.