as the title specifies, i have a problem with the fs api. I have made several test scripts to show you what i mean.
I am making an study program for people of my own language, so they can use Computercraft to start with the basics of programming. I want to make a config file for this. There is a way, where i just pin the whole config in the startup of the pc, and make it use strings for global use, but that would be unnecessary since there already is a api for that. I have been struggling with this for a long time now, and would like to know if this is an error on my side or on the Computercraft side.
What you need to know:
I never have errors while doing this. Only when i try to use the nil value for something that it ain't meant for.
Also i am fairly new in lua, i learned the whole language so far in 2 weeks. So there are some things i need to learn.
I know: for, if, when, function, variables, tables, #, events, peripheral, rednet, and the rest below this level of programming.
Also i have searched a lot for this error, but the only post i find are human errors, or things that are not dedicated to my problem.
The error:
none, literally, none. it returns a nil value every time i try to use the file.read() thing.
I did the following:
First, i copied the exact same code from some one else, which used the io api, and seemed to work just fine for him.
I made a test script (2 total, i tried io to, but that's completely new ground for me)
scripts:
For the writing i used a script called write:
local table = { 'test' } --Not needed, i know, but just for testing.
local file = fs.open('dataA', 'w')
file.write(table[1])
file.close()
local file = fs.open('dataB', 'w')
file.writeLine('Test B')
file.close()
For the reading i used a script called read:
local file = fs.open('dataA', 'r')
local table = file.readAll()
print('read all:\n', table[1])
local table = file.readLine()
print('read line:\n', table)
file.close()
local file = fs.open('dataB', 'r')
local table = file.readAll()
print('read all (B)/>:\n', table[1])
local table = file.readLine()
print('read line (B)/>:\n', table)
file.close()
print 'done'
When you use the writing script, It makes the following files:
dataA:
test
dataB:
Test B
When i use the reading script, it outputs the flowing:
>test2
read all:
read line:
read all (B)/>:
read line (B)/>:
done
> _
As you can see it won't output a thing. I have done this with the lua command prompt on the pc yesterday, and still nothing. for readAll() it returns a table, which is empty. For the readLine, it returns a nil. This is very confusing for me, since i have no idea what's going on here. Did i make a mistake? And why won't it give me an error if that's the case?
I have the patience to wait for an answer, but it's really bugging me when i'm studying.
Greetings from the Fox.