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

problem with a simple menu that will be used in an API

Started by Timo_Ho, 22 July 2014 - 02:16 PM
Timo_Ho #1
Posted 22 July 2014 - 04:16 PM
I need help with this code:

function menu(...)
arg = {...}
  x = 1
while true do
  if arg[x] == nil then
   break
  end
  x = x + 1
end
y = 2
  print("["..arg[1].."]")
while true do
  if y > x then
   break
  end
  print(arg[y])
  y = y + 1
end
mPos = 1
while true do
  event, key = os.pullEvent("key")
  if key == 200 then
   if mPos < x then
	mPos = mPos + 1
   else
	mPos = 1
   end
  end
  if key == 208 then
   if mPos > 1 then
	mPos = mPos - 1
   else
	mPos = x
   end
  end
  if key == 28 then
   break
  end
  y = 1
  while true do
   if y > x then
	break
   end
   if mPos == y then
	print("["..arg[y].."]")
   else
	print(arg[y])
   end
   y = y + 1
  end
end
end
Edited by
Cranium #2
Posted 22 July 2014 - 04:18 PM
You're not telling us what errors - if any - you're having.
Timo_Ho #3
Posted 22 July 2014 - 08:23 PM
oh sorry. The error is at line 67 it says attempt to concenate string and nil the code at this line is. print("["..arg[y].."]")
flaghacker #4
Posted 22 July 2014 - 09:03 PM
Your loop to count the lenght of arg (x) counts one to many. Remove that part and use "x = #arg" instead. The "#" returns the lenght of a string or table, only counting the following numerically indexed values, just like your attempt.
Edited on 22 July 2014 - 07:05 PM
Timo_Ho #5
Posted 23 July 2014 - 02:27 PM
thanks that's helped :)/> :)/> :)/> !!!