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

CC Menu, Chain Of Errors

Started by revjoe, 31 July 2014 - 01:20 PM
revjoe #1
Posted 31 July 2014 - 03:20 PM
I have been trying to use this code to create working menus and so far havent had many problems but today i have created this one and all im getting is errors and as i fix one another appears. Can anyone help plz.

local function menu(...) -- ver 0.1
    local sel = 1
    local list = {...}
    local offX,offY = term.getCursorPos()
    local curX,curY = term.getCursorPos()
    while true do
		    if sel > #list then sel = 1 end
		    if sel < 1 then sel = #list end
		    for i = 1,#list do
				    term.setCursorPos(offX,offY+i-1)
				    if sel == i then
						    print("["..list[i].."]")
				    else
						    print(" "..list[i].." ")
				    end
		    end
		    while true do
				    local e,e1,e2,e3,e4,e5,e6 = os.pullEvent()
				    if e == "key" then
						    if e1 == 200 then -- up key
								    sel = sel-1
								    break
						    end
						    if e1 == 208 then -- down key
								    sel = sel+1
								    break
						    end
						    if e1 == 28 then
								    term.setCursorPos(curX,curY)
								    return list[sel],sel
						    end
				    end
		    end
    end
end
-- Example Usage
term.clear()
term.setCursorPos(1,1)
print("Uber Teleport Hub- RevJoe's Slipstream Transport System")
term.setCursorPos(2,2)
print("Please select Option")
local selection = menu("Teleport 1","Teleport 2","Teleport 3","Teleport 4","Teleport 5","Teleport 6","Teleport 7","Teleport 8","VIP Teleport","EXIT")

if selection == "Teleport 1" then
    term.clear()
    term.setCursorPos(1,1)
    print("Activating Teleport, Please Hurry To Teleporter")
    sleep(1.5)
    redstone.setBundledOutput("back",colors.yellow,true)
    sleep(1)
    redstone.setBundledOutput("bottom",colors.yellow,false)
    os.reboot()
    end
elseif selection == "Teleport 2" then
    term.clear()
    term.setCursorPos(1,1)
    print("Activating Teleport, Please Hurry To Teleporter")
    sleep(1.5)
    redstone.setBundledOutput("back",colors.yellow,true)
    sleep(1)
    redstone.setBundledOutput("bottom",colors.yellow,false)
    os.reboot()
    end
elseif selection == "Teleport 3" then
    term.clear()
    term.setCursorPos(1,1)
    print("Activating Teleport, Please Hurry To Teleporter")
    sleep(1.5)
    redstone.setBundledOutput("back",colors.yellow,true)
    sleep(1)
    redstone.setBundledOutput("bottom",colors.yellow,false)
    os.reboot()
    end
elseif selection == "Teleport 4" then
    term.clear()
    term.setCursorPos(1,1)
    print("Activating Teleport, Please Hurry To Teleporter")
    sleep(1.5)
    redstone.setBundledOutput("back",colors.yellow,true)
    sleep(1)
    redstone.setBundledOutput("bottom",colors.yellow,false)
    os.reboot()
    end
elseif selection == "Teleport 5" then
    term.clear()
    term.setCursorPos(1,1)
    print("Activating Teleport, Please Hurry To Teleporter")
    sleep(1.5)
    redstone.setBundledOutput("back",colors.yellow,true)
    sleep(1)
    redstone.setBundledOutput("bottom",colors.yellow,false)
    os.reboot()
    end
elseif selection == "Teleport 6" then
    term.clear()
    term.setCursorPos(1,1)
    print("Activating Teleport, Please Hurry To Teleporter")
    sleep(1.5)
    redstone.setBundledOutput("back",colors.yellow,true)
    sleep(1)
    redstone.setBundledOutput("bottom",colors.yellow,false)
    os.reboot()
    end
elseif selection == "Teleport 7" then
    term.clear()
    term.setCursorPos(1,1)
    print("Activating Teleport, Please Hurry To Teleporter")
    sleep(1.5)
    redstone.setBundledOutput("back",colors.yellow,true)
    sleep(1)
    redstone.setBundledOutput("bottom",colors.yellow,false)
    os.reboot()
    end
elseif selection == "Teleport 8" then
    term.clear()
    term.setCursorPos(1,1)
    print("Activating Teleport, Please Hurry To Teleporter")
    sleep(1.5)
    redstone.setBundledOutput("back",colors.yellow,true)
    sleep(1)
    redstone.setBundledOutput("bottom",colors.yellow,false)
    os.reboot()
    end
elseif selection == "VIP Teleport" then
    term.clear()
    password = "level2"
    term.setCursorPos(1,1)
    print("VIP Access Only, Please Enter Security Code:-")
    pass = read("*")
    if pass == password then
    print("Security Code Accepted, VIP Teleport Activating")
    sleep(2)
    redstone.setBundledOutput("back",colors.orange,true)
    sleep(5)
    redstone.setBundledOutput("back",colors.orange,false)
    os.reboot()
    else
    term.clear()
    term.setCursorPos(1,1)
    print("Wrong Code Entered, Better Luck Next Time")
    sleep(0.5)
    os.reboot()
    end
end
Lyqyd #2
Posted 31 July 2014 - 03:22 PM
What is the error that you get with this version of the code?
Cranium #3
Posted 01 August 2014 - 01:10 AM
I think the main problem you are having is the numerous ends you have in your if statements. There should only ever be a single if, and a single end in those statements. Proper structure should be:

if something then

elseif somethingElse then

elseif somethingEntirelyElse then

else ifNothinElseThanAbove then

end
revjoe #4
Posted 01 August 2014 - 01:54 PM
had to do some fiddling to get it running but was the numerous end statements. Thank You for your help