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

Help with a typing program using tables.

Started by axel.codeFail(), 14 October 2014 - 06:53 PM
axel.codeFail() #1
Posted 14 October 2014 - 08:53 PM
I'm trying to make a typing program that will take user input and place it into a table for later use. Everything works fine until I press backspace. I have the backspace placed into the function to remove the last item placed into the table, but I get the error [string "test"]:20: table index is nil.


function draw(dx1,dy1,dx2,dy2,dcol)
  for a=dx1,dx2 do
	for b=dy1,dy2 do
	  term.setCursorPos(a,B)/>/>
	  term.setBackgroundColor(dcol)
	  term.write(" ")
	end
  end
end

repeat
  input={}
  inputnum=0
  event={os.pullEvent()}
  if event[1]=='char' then
	term.write(event[2])
	table.insert(input,event[2])
	inputnum=inputnum+1
  elseif event[1]=='key' and event[2]==14 then
	input[i]=nil
	inputnum=inputnum-1
	ix=inputnum+17
	draw(ix,12,ix,12,colors.white)
  end
until event[1]=='key' and event[2]==28
axel.codeFail() #2
Posted 14 October 2014 - 09:09 PM
Did you hear that? I just face palmed so hard that it broke the sound barrier.

At line 20 I have

input[i]=nil

But the variable i is never defined. So never mind, this is solved.
Edited on 14 October 2014 - 07:10 PM
Evil_Bengt #3
Posted 15 October 2014 - 08:01 AM
haha nice! :D/>