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

fs error. Crash log saving.

Started by Goof, 16 February 2013 - 10:52 AM
Goof #1
Posted 16 February 2013 - 11:52 AM
Hey!

Im trying to make a Crashlog that displays a cool designed screen right before the crash. but. when i've made a "save Crash log" button and i clicked on it it shows me this:
Test:35: attempt to index ? (a nil value)


I think im wrong in the fs api, but im not sure.. i dont remember the fs api that much.

Spoiler

local events = {os.pullEvent()}
	if events[1] == "mouse_click" then
		if events[3] >= 17 and events[3] <= 34 and events[4] == 17 then
			term.clear()
			term.setBackgroundColor(colors.gray)
			term.clear()
			term.setCursorPos(1,1)
				fLNum = ("cLogs/crashlog001")
				if not fs.exists(fLNum) then
					local _rTime = textutils.formatTime(os.time()) -- gets the current time.
					sCLg = fs.open(fLNum, "w") -- Line 34
					sCLg.writeLine("-- Error report saved, ".._rTime) -- line 35 this line is the error?
					sCLg.writeLine(" ")
					sCLg.writeLine("================================")
					sCLg.writeLine(err)
					sCLg.writeLine("================================")
					sCLg.close()
					write("Crash log has been saved to: \n\n/crashlogs/"..filenum)
				end	
		end	
	end	


Thanks in advance!
OmegaVest #2
Posted 16 February 2013 - 12:13 PM
…It might be writeLine. Try using write, and append your own "\n" to it. If it still errors, then you will know there's something wrong with your file instantiation, not the writeLine. If it works, then writeLine is still being ornery, and you should just avoid them for now.
Goof #3
Posted 16 February 2013 - 12:17 PM
write() doesnt work either. but i changed so much… but nothing works.

(code:)

Spoiler

	local events = {os.pullEvent()}
	if events[1] == "mouse_click" then
		if events[3] >= 17 and events[3] <= 34 and events[4] == 17 then
			term.clear()
			term.setBackgroundColor(colors.gray)
			term.clear()
			term.setCursorPos(1,1)
				fLNum = ("cLogs/crashlog001")
				if not fs.exists(fLNum) then
					local _rTime = textutils.formatTime(os.time())
					function save()
						sFil = fs.open(fLNum, "w")
						sFil.write("-- Error report saved, ".._rTime)
						sFil.write(" ")
						sFil.write("================================")
						sFil.write(err)
						sFil.write("================================")
						sFil.close()
						return sFil
					end	
					if save() then
						write("Crash log has been saved to: \n\n/crashlogs/"..filenum)
					end
				end	
		end	
	end	


edit: but how can i then change the file installation
edit 2: well.. now it works when i type in "lol" in the sFil = fs.open("lol", "w") but how could i then change it so it would be the variable "fLNum" ?

EDIT 3: Everything works now.. i forgot to make the dir in the "cLogs" xD


Everything works now!