Posted 01 January 2013 - 08:30 AM
Hello peeps,
I tried following a tutorial on Youtube for what I thought was a nice piece of code, sad part is that the author did not put a link to the source… My programming skills are in beginner stage but I get the general idea.
When I run the code it outputs nothing… normally there would be errors to go about… so please help out :)/>
The video in question.
I tried following a tutorial on Youtube for what I thought was a nice piece of code, sad part is that the author did not put a link to the source… My programming skills are in beginner stage but I get the general idea.
When I run the code it outputs nothing… normally there would be errors to go about… so please help out :)/>
The video in question.
--[[ Local Variables ]]--
local termWidth, termHeight = term.getSize()
local selectedItem = 1
local InMainMenu = true
local InLightsMenu = false
--[[ Menu Methods ]]--
function Choice1()
term.clear()
term.setCursorPos(1,1)
term.write("test")
sleep(3)
end
function Choice2()
inLightsMenu = true
selectedItem = 1
while inLightsMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(lightsMenu)
event, key = os.pullEvent("key")
onKeypressed(key, lightsMenu)
end
end
function LightsOn()
rednet.send(45, "on")
inLightsMenu = false
selectedItem = 1
end
function LightsOff()
rednet.send(45, "off")
inLightsMenu = false
selectedItem = 1
end
function Exit()
inMainMenu = false
end
--[[ Menu Definitions ]]--
mainMenu = {
[1] = { text = "menu 1", handler = Choice1 },
[2] = { text = "Light Controls", handler = Choice2 },
[3] = { text = "Exit", handler = Exit }
}
lightsMenu = {
[1] = { text = "on", handler = LightsOn },
[2] = { text = "off", handler = LightsOff }
}
--[[ Printing Methods ]]--
function printMenu(menu)
for i=1, #menu do
if i == selectedItem then
print (">> "..menu[i].text)
else
print (" "..menu[i].text)
end
end
end
--[[ Handler Methods ]]--
function onKeyPressed( key, menu )
if key == keys.enter then
onItemSelected(menu)
elseif key == keys.up then
if selectedItem > 1 then
selectedItem = selectedItem -1
end
elseif key == keys.down then
if selectedItem < #menu then
selectedItem = selectedItem +1
end
end
end
function onItemSelected( menu )
menu[selectedItem].handler()
end
--[[ Main Method ]]--
function main()
while inMainMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key, mainMenu)
end
end
main()