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

[ERROR] attempt to call nil [SOLVED]

Started by BabyCodder, 02 April 2013 - 02:22 AM
BabyCodder #1
Posted 02 April 2013 - 04:22 AM
I have a problem with the following code:


function add()
if not fs.isDir("myNotes") then fs.makeDir("myNotes") end

local note = fs.open("myNotes/notes", "w")
print("Type your note.")
print("Or type 'exit' to reboot notes")
note = read()

if note == "exit" then
  ask()
else
note.writeLine( note )
note.close()
ask()
end
end

The error is on note.writeLine(note)
SuicidalSTDz #2
Posted 02 April 2013 - 04:28 AM
Instead of storing the function read() inside a variable, just do this:


local note = fs.open("lols","w")
print("Type your note")
note.writeLine(read())
note.close()
theoriginalbit #3
Posted 02 April 2013 - 04:28 AM
EDIT: nvm, ninja'd
BabyCodder #4
Posted 02 April 2013 - 04:33 AM
Instead of storing the function read() inside a variable, just do this:


local note = fs.open("lols","w")
print("Type your note")
note.writeLine(read())
note.close()
thanks!

Instead of storing the function read() inside a variable, just do this:


local note = fs.open("lols","w")
print("Type your note")
note.writeLine(read())
note.close()
What about the "exit" command?
faubiguy #5
Posted 02 April 2013 - 04:40 AM
Just change note in
note = read()
to some other variable name (like input), and use than same name when you check if its "exit". THat way it won't overwrite the opened file which is stored to note
BabyCodder #6
Posted 02 April 2013 - 04:43 AM
Just change note in
note = read()
to some other variable name (like input), and use than same name when you check if its "exit". THat way it won't overwrite the opened file which is stored to note
Odd. It works.
SuicidalSTDz #7
Posted 02 April 2013 - 04:52 AM
EDIT: Ninja'd

EDIT: nvm, ninja'd
Heh :P/>