Jump to content




[ERROR] attempt to call nil [SOLVED]


  • You cannot reply to this topic
6 replies to this topic

#1 BabyCodder

  • Members
  • 87 posts

Posted 02 April 2013 - 03: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)

#2 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 02 April 2013 - 03: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()


#3 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 02 April 2013 - 03:28 AM

EDIT: nvm, ninja'd

#4 BabyCodder

  • Members
  • 87 posts

Posted 02 April 2013 - 03:33 AM

View PostSuicidalSTDz, on 02 April 2013 - 03:28 AM, said:

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!

View PostSuicidalSTDz, on 02 April 2013 - 03:28 AM, said:

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?

#5 faubiguy

  • Members
  • 213 posts

Posted 02 April 2013 - 03: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

#6 BabyCodder

  • Members
  • 87 posts

Posted 02 April 2013 - 03:43 AM

View Postfaubiguy, on 02 April 2013 - 03:40 AM, said:

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.

#7 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 02 April 2013 - 03:52 AM

EDIT: Ninja'd

View Posttheoriginalbit, on 02 April 2013 - 03:28 AM, said:

EDIT: nvm, ninja'd
Heh :P





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users