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

Help from the menu

Started by Ka6a400kg, 18 March 2012 - 10:14 AM
Ka6a400kg #1
Posted 18 March 2012 - 11:14 AM
Hi all!
Help make a light menu for ComputerCraft please. :D/>/>
Luanub #2
Posted 18 March 2012 - 11:49 AM
See this for some help on making a menu http://www.computercraft.info/forums2/index.php?/topic/639-lua-cc-menu-how/
Liraal #3
Posted 18 March 2012 - 12:03 PM
i think i am going to write a tutorial about it. there certainly is a need for it :D/>/>
Ka6a400kg #4
Posted 18 March 2012 - 01:13 PM
You can write the menu at least 6-choice? :D/>/>
If you can please write. :)/>/>
Liraal #5
Posted 18 March 2012 - 01:20 PM

function CUI(m)
n=1
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]")
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
supply this code with a table (e.g. {"a","b"}) of options and it returns the number of the chosen one. I will feature it in a tutorial later on.
Ka6a400kg #6
Posted 18 March 2012 - 01:30 PM
/
Luanub #7
Posted 18 March 2012 - 10:50 PM
To give you something simple to start with you can make a simple menu like using print and if elseif statements..


print ("1) Option 1")
print ("2) Option 2")
print ("3) Option 3")
print ("4) Option 4")
print ("5) Option 5")
print ("6) Option 6")
print()
write ("Enter your selection: ")
local input = read()
if read == 1 then
-- do option 1 stuffs
elseif read == 2 then
-- do option 2 stuffs
-- and so on..
else
print ("invalid option selected")
end
Ka6a400kg #8
Posted 19 March 2012 - 01:35 PM
Menu created liraal better because you choose the arrow up / down. :D/>/>