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

Nil [error] in RP frame door program, with GUI

Started by Aerik, 04 June 2012 - 12:58 AM
Aerik #1
Posted 04 June 2012 - 02:58 AM
Hey guys,

I wrote a program to automatically open the frame door of my hangar, and got it working. However, after implementing some code for a nice GUI (based on a program by NitrogenFingers), I receive a nil error upon trying to move the selection by pressing the "down" arrow:
startup:102: attempt to index ? (a nil value)

(hopefully) relevant part of code:

local menustate = "main"
local mopt = {
["main"] = {
  options = {"open", "close", "quit"},
  draw = drawMain
}
}
function runMenu()
while true do
  term.clear()
  drawHeader()
  mopt[menustate].draw()
  local id, key = os.pullEvent("key")
  if key == 200 and select > 1 then select = select-1
  elseif key == 208 and select < #mopt[menustate].options then select = select+1
  elseif key == 28 then
   if mopt[menustate].options[select] == "quit" then break
   end
   if mopt[menustate].options[select] == "open" then
	openSeq()
   end
   if mopt[menustate].options[select] == "close" then
	closeSeq()
   end
  end
  menustate = mopt[menustate].options[select]
end
end

Entire code in the attachment.

I have no idea what is wrong, or how to fix it, so any help would be appreciated!
Thank you, in advance, for your time!

Aerik out.
my_hat_stinks #2
Posted 04 June 2012 - 03:55 AM
Your problem is line 131
menustate = mopt[menustate].options[select]

It's setting menustate to a menu you don't actually have in mopt
Aerik #3
Posted 04 June 2012 - 03:58 PM
Thank you! (Feels stupid)
my_hat_stinks #4
Posted 04 June 2012 - 04:08 PM
Thank you! (Feels stupid)

Don't feel stupid, everyone makes mistakes, and this one was pretty well hidden :)/>/>

Had to write debug messages into the code to find it (but then, it was pretty late… :D/>/>)