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

Reading File Set:14: Attempt To Index ? (A Nil Value)

Started by theeboris, 06 August 2013 - 03:23 AM
theeboris #1
Posted 06 August 2013 - 05:23 AM
Hello,

I'm busy with a program that make it possible for people to chance settings in LightOS (It is still not released). But if I use this code I get the error message: "set:14: attempt to index ? (a nil value)" . So if I do ap = h.readLine() then it returns nil, but why? I thought that this would be okay. Can somebody help me with this? Thanks :D/>


acreenx, screeny = term.getSize()
painttools.fill(1, screenx, 1, screeny, 256)
if fs.exists(".lightos/system/config/bluescreen") == false then
local sFile = ".lightos/system/config/bluescreen"
h = fs.open(sFile, "w")
  h.writeLine("false")
  h.writeLine("true")
  h.writeLine("true")
h.close()
end
while true do
local sFile = ".lightos/system/config/bluescreen"
h = fs.open("sFile", "r")
  ap = h.readLine()
  se = h.readLine()
  er = h.readLine()
h.close()
term.setCursorPos(1,1)
print("Auto pastebin:"..ap)
print("Smiley:"..se)
print("Error report:"..er)
--Here comes some more code if the file thing works
end
svdragster #2
Posted 06 August 2013 - 07:14 AM

acreenx, screeny = term.getSize()
I think you mean screenx :P/>

Also

h = fs.open("sFile", "r")
should be

h = fs.open(sFile, "r")
Or it would open a file called "sFile" instead of opening ".lightos/system/config/bluescreen"
theeboris #3
Posted 06 August 2013 - 07:55 AM
Wow! Thanks bro :D/> That you have see that. Good job :D/> I give you credits in the .lightos/about.txt and topic if I publish it ;)/>