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

Script printing off "12" before I even get to input

Started by libraryaddict, 07 March 2012 - 10:51 AM
libraryaddict #1
Posted 07 March 2012 - 11:51 AM
Spoiler

total = 0
file = read()

function Clear()
term.clear()
term.setCursorPos(1,1)
end

local h = fs.open(file, "r")
clear()
function Print()
  if not line then
    if total < 15 then
      local line = h:readLine()
      print(line)
      total = total+1
      line = nil
      Print()
    elseif total == 15 then
      sleep(1)
      event,param1 = os.pullEvent()
      if event == "key" and param1 == 57 then
        total = 0
        clear()
        Print()
      end
    end
  elseif line then
    break
  end
end
h:close()

When I run this I immediately get "12"
I dont even get to input text
Advert #2
Posted 07 March 2012 - 12:14 PM
the '12' is probably because you're not managing your variables very well: I don't see 'clear' defined (you defined Clear).

You're also trying to use the local variable line when it doesn't exist.

In addition to that, you're only using os.pullEvent once, meaning that if you trigger that event somehow, you'll exit the program.