This is the line of code (145 lines);
Spoiler
-- [[ Local Variables ]]--
local termWidth, termHeight = term.getSize()
local selectedItem = 1
local inMainMenu = true
local inReadme = false
--[[ Menu Methods ]]--
function Choice1()
term.clear()
term.setCursorPos(1,1)
term.write("Hello my name is"..os.getComputerLabel())
sleep(2)
end
function readme()
inReadme = true
selectedItem = 1
while inReadme do
term.clear()
term.setCursorPos(1,1)
printMenu(readmeMenu)
event, key = os.pullEvent("key")
onKeyPressed(key, readmeMenu)
end
end
function General()
term.clear()
term.setCursorPos(1,1)
term.write("Stuff")
sleep(2)
selectedItem = 1
end
function Credits()
term.clear()
term.setCursorPos(1,1)
term.write("Stuff")
sleep(2)
selectedItem = 1
end
function Changelog()
term.clear()
term.setCursorPos(1,1)
term.write("Stuff")
sleep(2)
selectedItem = 1
end
function Return()
term.clear()
term.setCursorPos(1,1)
inReadme = false
selectedItem = 1
end
function Exit()
inMainMenu = false
end
--[[ Menu Definitions ]]--
mainMenu = {
[1] = { text = "Choice 1", handler = Choice1 },
[2] = { text = "Readme", handler = Readme },
[3] = { text = "Exit", handler = Exit }
}
readmeMenu = {
[1] = { text = "General Information", handler = General },
[2] = { text = "Credits & Acknowledgements", handler = Credits },
[3] = { text = "Changelog", handler = Changelog },
[4] = { text = "Return", handler = Return }
}
--[[ 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 Method ]]--
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()
The code works fine until line 127 when "nokhios:127: attempt to call nil" happens. However, this only happens when I choose the "readme" option in the menu. It works fine in the "main menu", and removing said code still has the same error on a blank line… And if anyone asks, yes I basically followed along a tutorial so I can learn by doing. Said tutorial can be found here
Here's the specific snippet;
Spoiler
function onItemSelected( menu )
menu[selectedItem].handler()
end