112 posts
Posted 21 October 2014 - 02:08 PM
Hey There,
using the following snippet, throws the error Line 3: attempt to index (a nil value)
local test = { name = "Zag", planet = "Earth"}
local file = fs.open("Planets", "w")
file.write(textutils.serialize(test))
file.close()
what the hell is wrong?
1583 posts
Location
Germany
Posted 21 October 2014 - 03:10 PM
file.write isn't the exact problem. the actual problem is, that fs.open(<some args>,<here>) returns nil. This can happen when the file is read only for example.
112 posts
Posted 21 October 2014 - 03:31 PM
I had some similar thoughts, but when i flick off the switch "Read only" with the Windows-Explorer, it is switched on the next time i look into those attributes.
Every other prog like Notepad ++ can write to its files (even with READ-ONLY = ON) and save it, just the computercraft mod is not writing to a file.
What can i do? Virus, Malware?
1583 posts
Location
Germany
Posted 21 October 2014 - 04:12 PM
go into the interactive lua prompt (enter "lua" in the shell) and do "fs.isReadOnly(<filename>)" and tell us if it return true or false
7083 posts
Location
Tasmania (AU)
Posted 21 October 2014 - 04:16 PM
It's may just be that the file is locked. Files typically become so when programs open them (at the option of the program in concern). For example, if you tell a ComputerCraft computer to open a file, it'll typically lock it (which is why that "close" call is important - if you lose the file handle before using it, you may have to reboot the computer in concern before it can open the file again).
You can tell if a file is locked in that Windows Explorer will refuse to delete it, instead stating that it's "in use". It may well be that Notepad++ is what's holding the lock. The odds of a virus or piece of malware being involved are below remote.
Also - bear in mind that ComputerCraft enforces limits on the amount of data a given computer can store. One meg, if memory serves. Double check you're not exceeding that.
112 posts
Posted 21 October 2014 - 04:57 PM
first to to freak100's thought : it returns false
My code worked, unchanged for the last 2 weeks or so, even when Notepad++ was showing the opened "data-file". Since two days now, my "data-file" is not writable. When i copy a backup of the data file to my computers folder, it can be read and used normaly, but when i call a function to write new entries to that file, the file-content gets erased. The file is still inside the folder, but is empty. Of course i am aware that i can not read a empty file but changing the code to write the file again, i get this error message mentioned above.
It's not possible to write any file, even the little snipped from above does not work.
I'm not sure how to check, if i'm exceeding some memory.
I'm sure that my tables, that are in use. are not very bulky. I use a peripheral network of about 90 MFR-Deep-Storage-Units to store items. The program checks for DSU's inside the network and writes them to a file with about 7 values per entry. Every time i put up new dsu's, i will run this function to store the new dsu's and it's content-item. Later, i can suck items from the dsu's to a crafting turtle, that will craft items, refering to a second table, that stores recipes. Those recipes are written to a second file, reading a workbench where i set up the recipe. The second "recipe"-table has 7 entries with 11 values. The Only computers that run in my world are this main-crafting-computer, it's turtle, and a pocket PC that opens a door on a 4th computer, listening to a rednet message, coming from the pocket to open the main gate into my personal area51.
I think this is not very extensive.
I may not write any file even if its just one letter!!!! I'm begining to think of being trapped inside a demo-version or so… :)/>
Edit: Ah sorry: Even with no notepad++ i am not able to write a file…
Edited on 21 October 2014 - 03:03 PM
1583 posts
Location
Germany
Posted 21 October 2014 - 10:16 PM
It sounds like you are opening the files with fs.open(<name>,"w") which isn't right when you want to keep the content and put your cursor at the end use "a" as mode which stands for "append". And if you can't even open the file in N++/any other editor it most likely is opening the file somewhere, but didn't close the handle properly.
3057 posts
Location
United States of America
Posted 21 October 2014 - 11:04 PM
It sounds like you are opening the files with fs.open(<name>,"w") which isn't right when you want to keep the content and put your cursor at the end use "a" as mode which stands for "append". And if you can't even open the file in N++/any other editor it most likely is opening the file somewhere, but didn't close the handle properly.
Append would be if he want to add info to the end. He wants to replace the current contents of the file with the updated table.
112 posts
Posted 22 October 2014 - 01:55 AM
Thats right king, the file should be written with all new content. Nevertheless what it was before. It's meaning is "don't care what you read before, write what you got". If i break a dsu because i don't need it anymore, the new version has to give the current setup.
But it's not what you all think, it's not possible to write any file. It's not my dsu-file, it's any file.
Second: it's possible to open the data file with n++, but every time i rewrite it with my program, it's empty, erased, deleted content. But the file is there with 0kb.
Edited on 22 October 2014 - 12:10 AM
7083 posts
Location
Tasmania (AU)
Posted 22 October 2014 - 02:03 AM
I'm not sure how to check, if i'm exceeding some memory.
fs.getFreeSpace()
112 posts
Posted 22 October 2014 - 03:18 AM
I think Bomb Bloke get's acceptance of this bid. The fs.getFreeSpace("/") get's me a value of 0. In the highest friendlyness i appologise for my inconvenience. it's a thing i never got aware with..Got rid of unnecessary files inside the folder and "tataaaa", it works again.
But you have to know that first.
Sorry guys, and thank you Bomb Bloke.You always got the right flair.
47 posts
Posted 22 October 2014 - 08:38 PM
How do you just put 1MB of data on a computercraft computer I always have atleast 90% space free
3057 posts
Location
United States of America
Posted 22 October 2014 - 09:28 PM
How do you just put 1MB of data on a computercraft computer I always have atleast 90% space free
Install multiple operating systems, I imagine.
112 posts
Posted 26 October 2014 - 09:20 AM
Or mistakenly copy a file to a direcrory it doesn't belong to.