No edit summary |
No edit summary Tag: Visual edit |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{ApiReference |
{{ApiReference |
||
|name=menuitem |
|name=menuitem |
||
− | |shortdesc=Adds a custom item to the |
+ | |shortdesc=Adds a custom item to the PICO-8 menu. |
|index||The item index, a number between 1 and 5. |
|index||The item index, a number between 1 and 5. |
||
|label|optional|The label text of the menu item to add or change. |
|label|optional|The label text of the menu item to add or change. |
||
|callback|optional|A Lua function to call when the user selects this menu item. |
|callback|optional|A Lua function to call when the user selects this menu item. |
||
}} |
}} |
||
− | To remove a previously added item, call <code>menuitem(i)</code> where i is the index of the item to remove. |
+ | To remove a previously added item, call <code>menuitem(i)</code> where <code>i</code> is the index of the item to remove. |
+ | |||
+ | {{Version|0.2.0}} |
||
+ | |||
+ | If the callback returns true, the pause menu remains open. |
||
+ | |||
+ | Menu item can detect Left and Right button presses. The callback takes a single parameter that is a bitfield of Left (0) and Right (1). |
||
+ | |||
+ | It can also detect O (4), X (5) and Pause (6), but it cannot distinguish them (if any is pressed, the parameter is the bitmask sum = 16+32+64 = 112). |
||
+ | |||
+ | Combining all these properties allows a developer to add a numeric field tuner (decrease on Left, increase on Right, and possibly reset on X). |
||
== Examples == |
== Examples == |
||
Line 16: | Line 26: | ||
end |
end |
||
menuitem(2, "show hints", display_hints) |
menuitem(2, "show hints", display_hints) |
||
+ | |||
+ | -- v0.2.0 |
||
+ | menuitem(3, "foo", function(b) if (b&1 > 0) then printh("left was pressed") end end) |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Revision as of 18:39, 2 July 2021
menuitem( index, [label,] [callback] )
- Adds a custom item to the PICO-8 menu.
- index
-
- The item index, a number between 1 and 5.
- label
-
- The label text of the menu item to add or change.
- callback
-
- A Lua function to call when the user selects this menu item.
To remove a previously added item, call menuitem(i)
where i
is the index of the item to remove.
New in PICO-8 0.2.0.
If the callback returns true, the pause menu remains open.
Menu item can detect Left and Right button presses. The callback takes a single parameter that is a bitfield of Left (0) and Right (1).
It can also detect O (4), X (5) and Pause (6), but it cannot distinguish them (if any is pressed, the parameter is the bitmask sum = 16+32+64 = 112).
Combining all these properties allows a developer to add a numeric field tuner (decrease on Left, increase on Right, and possibly reset on X).
Examples
menuitem(1, "restart puzzle", function() reset_puzzle() sfx(10) end)
function display_hints()
hint_shown = level_id
end
menuitem(2, "show hints", display_hints)
-- v0.2.0
menuitem(3, "foo", function(b) if (b&1 > 0) then printh("left was pressed") end end)