This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
kelechi96's profile picture

Creating a selection menu in Lua

Started by kelechi96, 04 March 2012 - 11:56 AM
kelechi96 #1
Posted 04 March 2012 - 12:56 PM
Does anybody know how I can do this ?

Basically all it is is that you press up and down to select an option, just like the LILO bootloader … and come to think of it the GRUB bootloader too.
Liraal #2
Posted 04 March 2012 - 01:24 PM
Like this:


function CUI(m)
local n=1
local l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, "["..m[i].."]") else print(i, m[i]) end
end
print("Select a number[arrow up/arrow down]")
local a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
kelechi96 #3
Posted 04 March 2012 - 02:53 PM
Thank you !
coolblockj #4
Posted 05 March 2012 - 11:59 PM
[INSERT DERP COMMENT HERE]
(Lol i was being stupid and posted a comment that didnt make sense)
Advert #5
Posted 06 March 2012 - 12:15 AM
Here, take a look at this: http://www.computercraft.info/forums2/index.php?/topic/398-help-improving/

I posted a sample somewhere in there.