Posted 03 August 2013 - 09:59 AM
Title: equals expected on term.setCursorPos(1,1)
I am trying to write a function that generates a menu with arrow key option switching. I would like to make use of a table input where the value of each key is the option, due to this function being in scope of a larger project. When run this code returns the error: BIOS:337: [string "menu.lua"] 27: '=' expected. I am pretty sure that setCursorPos does not require any equals leading me to think there was a different error in the function causing it. Improvements tot he code is gladly accepted as long as they are explained since I am pretty new to lua as a programming language and would like to learn.
I am trying to write a function that generates a menu with arrow key option switching. I would like to make use of a table input where the value of each key is the option, due to this function being in scope of a larger project. When run this code returns the error: BIOS:337: [string "menu.lua"] 27: '=' expected. I am pretty sure that setCursorPos does not require any equals leading me to think there was a different error in the function causing it. Improvements tot he code is gladly accepted as long as they are explained since I am pretty new to lua as a programming language and would like to learn.
function generateMenu(options)
term.clear()
n = 1
while true do
sleep(1)
term.clear()
m = n + 1
print("Please select an option")
for i=1, 1000000, 1 do
if options[i] == nil then
break
else
print(options[i])
end
end
term.clearLine(m)
term.setCursorPos(1,m)
print("[ "..options[n].." ]")
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) -- line 27
return n
end
--testing the function
opt = {}
opt[1] = "first option"
opt[2] = "seccond option"
opt[3] = "third option"
result = generateMenu(opt)
print(result)