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

Can't cocantanate string and nil on files.

Started by leftcatcher, 09 October 2012 - 10:10 PM
leftcatcher #1
Posted 10 October 2012 - 12:10 AM
Okay, so. I thought this sort of thing would work, but for some reason, it does not. The problem is that when I set a variable equal to something, and then try to create a file named after it, it gives me the error "Can't cocantanate string and nil" or whatever. It works if I set the variable equal to a string, but for what I'm doing, it can't be set to one. The error is on line four.


rsoutput = top
currentB = false
fs.makeDir("saves")
  local file = fs.open("saves/"..rsoutput, "w") --This line.
  file.writeLine(currentB)
  file.close()

And I also tried this:


rsoutput = top
currentB = false
fs.makeDir("saves")
local file = fs.open("saves/"..tostring(rsoutput), "w")
file.writeLine(currentB)
file.close()

The latter one actually goes through with making it, but the file is called "nil" instead of "top" like it should be, so it's not working, and I can't seem to figure it out. ._.
PixelToast #2
Posted 10 October 2012 - 12:15 AM
nil is not a string, its nothing, when you only type top, it will look for a variable called top and will return nil
top needs to be a string, encase it in quotes