Jump to content




[Lua] [Error] "attempt to call nil" fs.close variables


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

#1 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 25 November 2012 - 08:56 AM

Code:

local zm = 'zmienne'
term.clear()
term.setCursorPos(1,1)
print "Status Wlaczania: "
if fs.exists(zm) then
  term.setCursorPos(1,2)
  print "Zmienne [X]"
 else
  term.setCursorPos(1,2)
  print "Zmienne [ ]"
  fs.open(zm, "w")
  fs.close(zm)
  term.setCursorPos(1,2)
  sleep(1)
  term.clearLine()
  print "Zmienne [X]"
end
Error:
startup:12: attempt to call nil

zmienne is in polish in english it means variables :D/>

#2 dissy

  • Members
  • 181 posts

Posted 25 November 2012 - 09:01 AM

fs.open returns a file handle, which is what needs passed to close, not the file name.

local h = fs.open(zm, "w")
h.close()

#3 exploder

  • Members
  • 69 posts
  • LocationLatvia

Posted 25 November 2012 - 09:04 AM

View Postmibac138, on 25 November 2012 - 08:56 AM, said:

Code:
local zm = 'zmienne' term.clear() term.setCursorPos(1,1) print "Status Wlaczania: " if fs.exists(zm) then term.setCursorPos(1,2) print "Zmienne [X]" else term.setCursorPos(1,2) print "Zmienne [ ]" fs.open(zm, "w") fs.close(zm) term.setCursorPos(1,2) sleep(1) term.clearLine() print "Zmienne [X]" end
Error: startup:12: attempt to call nil zmienne is in polish in english it means variables :D/>/>/>

Maybe try this:

local zm = 'zmienne'
term.clear()
term.setCursorPos(1,1)
print "Status Wlaczania: "
if fs.exists(zm) then
  term.setCursorPos(1,2)
  print "Zmienne [X]"
else
  term.setCursorPos(1,2)
  print "Zmienne [ ]"
  fs.open(zm, "w")
  fs.close()
  term.setCursorPos(1,2)
  sleep(1)
  term.clearLine()
  print "Zmienne [X]"
end

Tell me if that's what you wanted.

#4 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 25 November 2012 - 09:06 AM

OK but when i'm editing file "zmienne" and if i'm click any button it's writing

edit:363: bad argument: string expected, got nil

#5 dissy

  • Members
  • 181 posts

Posted 25 November 2012 - 09:20 AM

View Postexploder, on 25 November 2012 - 09:04 AM, said:

Maybe try this:

That is still the same incorrect usage of fs.close. See my above post.

#6 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 25 November 2012 - 09:39 AM

This dont work...

#7 dissy

  • Members
  • 181 posts

Posted 25 November 2012 - 10:00 AM

My code is tested and verified, and it works.
If you are getting an error, we need to see both the error and the code to help.

#8 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 25 November 2012 - 11:03 AM

Posted Image


Posted Image


Posted Image

Maybe give me yours code

#9 dissy

  • Members
  • 181 posts

Posted 25 November 2012 - 11:12 AM

My code was
h = fs.open("newfile", "w")
h.close()

It creates the new file, closes the file handle, and no errors.

Posted Image

#10 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 25 November 2012 - 01:33 PM

Is the file in rom? If it is, you can't delete it

#11 ChunLing

  • Members
  • 2,027 posts

Posted 26 November 2012 - 07:39 AM

Post the current version of the code, incorporating the repair suggested by dissy, and the error message for that version. Don't tell us you've got new error messages without posting the code that produced them.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users