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

Script crashes after running once?

Started by DaWooShit, 24 August 2012 - 08:35 PM
DaWooShit #1
Posted 24 August 2012 - 10:35 PM
I'm currently working on a simple program which reads from a file and displays the text on a monitor, but I have run into a problem: The script crashes when it tries to run the second time and this error message pops up: "bios:25: bad argument: double expected, got nil".

I have tried to fix this problem myself, but whatever I do the same problem occurs.

Code - http://pastebin.com/bt9yvgKT:

Side="top"
Document="info.txt" --Name of the file.
Speed=10 --Typing speed multiplier
Runtimes=0 --use 0 to run the text forever.
Triggerbyredstone="none" --Change to the side you wish to use if you want to use a redstone signal.

Runlimited=false

if Triggerbyredstone~="none" then
while rs.getInput(Triggerbyredstone)==false do
  sleep(0.1)
end
end

if Runtimes<0 then
Runlimited=true
else
Runtimes=1
end

file = io.open(Document, "r")

if file==nil then
print("Do document was found!")
print("The program was unable to read from the file")

else

while Runtimes>0 do
  file = io.open(Document, "r")
  A = file:read()
  Linecount=tonumber(A)
  Linecount=Linecount-1

  while Linecount>0 do
   A = file:read()
   mon = peripheral.wrap(Side)term.redirect(mon)
   textutils.slowPrint(A,Speed)
   Linecount=Linecount-1
  end
  term.restore()

  if Runlimited==true then
   Runtimes=Runtimes-1
  end
  Sleeptime=30/Speed
  file:close()
  sleep()
  term.clear(Sleeptime)
  term.setCursorPos(1,1)
end
end

Hope you guys are able to help a clueless LUA noob out here…
predatorxil #2
Posted 24 August 2012 - 10:45 PM
I would suggest going into notepad++ or waht ever you used, find line 25, and review that line for errors, also, it might be the line before tha-> if file==nil then
try the line if file == nil then
DaWooShit #3
Posted 24 August 2012 - 11:24 PM
Pretty sure the "25" is an error-code and not the line where the error is found.
DaWooShit #4
Posted 25 August 2012 - 11:04 AM
I have fixed the problem myself.. Sorry for posting.
Cranium #5
Posted 25 August 2012 - 04:10 PM
Could you post your resolution? It helps some of the other coders to know how you fixed your problem.