file = fs.open("/rom/programs/computer/Nightfall/savedvars/SFGarageDoorStatus.txt", "w")
if file then
input = read()
file.write(input)
file.close()
print("Saved "..input..".")
else
print("Failed")
end
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[LUA][Help] writing text to a file
Started by remiX, 07 October 2012 - 10:20 PMPosted 08 October 2012 - 12:20 AM
I'm using this code to write things into a file and it isnt working. It doesn't give an error but it says failed, therefor it doesn't find the file. But I have it there and have tested it with "r" to read. When I change the "w" to "r" and remove file.write(input) it works. So i got a feeling file.write(input) is wrong somehow but I cant see how…
Posted 08 October 2012 - 12:32 AM
The /rom/ directory is restricted from editing by programs.
Posted 08 October 2012 - 12:42 AM
This fact was even mentioned in your previous topic asking a similar question:
Of course, you won't be able to write to it there (can't write to rom), but you should be able to read it fine with the correct path.
Posted 08 October 2012 - 12:57 AM
Ah my bad, so where can you write files safely?
Posted 08 October 2012 - 01:02 AM
The best place to write files is in the same directory as the script that's doing the writing.
Posted 08 October 2012 - 01:17 AM
The best place to write files is in the same directory as the script that's doing the writing.
Okay, I put the file in the same folder as the script that is doing it but it still doesn't work. Even if I delete the lol.txt file it still wants me to type it therefor indicating that it found the file :? It doesn't write inside the file though .
file = fs.open("lol.txt", "w")
if file then
input = read()
file.write(input)
file.close()
print("read "..input..".")
else
print("Failed")
end
Posted 08 October 2012 - 01:25 AM
The program isn't in rom either, right?
Posted 08 October 2012 - 01:36 AM
The program isn't in rom either, right?
Nope, it's only in the exact folder where the code is
Posted 08 October 2012 - 02:40 AM
I just read your post as "the code is where the code is".
Is the code in your /saves/[you world name]/computer/[your computer id]?
Is the code in your /saves/[you world name]/computer/[your computer id]?
Posted 08 October 2012 - 02:59 AM
I just read your post as "the code is where the code is".
Is the code in your /saves/[you world name]/computer/[your computer id]?
I'm using a multiplayer server, might this be the problem?
Path for code: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfallsave.lua
Path for file: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfalllol.txt
Posted 08 October 2012 - 05:31 AM
Again, you have the file in the rom folder, not in a computer's folder. Somewhere in world/computer/<computerID> should be where it's at, not in the rom.
Posted 08 October 2012 - 06:03 AM
I just read your post as "the code is where the code is".
Is the code in your /saves/[you world name]/computer/[your computer id]?
I'm using a multiplayer server, might this be the problem?
Path for code: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfallsave.lua
Path for file: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfalllol.txt
Future notice,
when someone asks for the path.. they mean in CC, not on your literal computer… thank you Mr. Hurrdurr
Posted 08 October 2012 - 09:55 PM
I just read your post as "the code is where the code is".
Is the code in your /saves/[you world name]/computer/[your computer id]?
I'm using a multiplayer server, might this be the problem?
Path for code: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfallsave.lua
Path for file: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfalllol.txt
Future notice,
when someone asks for the path.. they mean in CC, not on your literal computer… thank you Mr. Hurrdurr
Yeah I had no clue what to name my hdd…
The file im trying to write to now is at path: H:/Hurrdurr/Games/MC/Tekkit_Server_3.1.2/RandomStuff/computer/388/SFGarageDoorStatus.txt
– RandomStuff is the name of the world map. I've tried that path and "RandomStuff/computer/388/SFGarageDoorStatus.txt" but it doesn't work.
How do I get it work?
Posted 09 October 2012 - 12:39 AM
I just read your post as "the code is where the code is".
Is the code in your /saves/[you world name]/computer/[your computer id]?
I'm using a multiplayer server, might this be the problem?
Path for code: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfallsave.lua
Path for file: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfalllol.txt
Future notice,
when someone asks for the path.. they mean in CC, not on your literal computer… thank you Mr. Hurrdurr
Yeah I had no clue what to name my hdd…
The file im trying to write to now is at path: H:/Hurrdurr/Games/MC/Tekkit_Server_3.1.2/RandomStuff/computer/388/SFGarageDoorStatus.txt
– RandomStuff is the name of the world map. I've tried that path and "RandomStuff/computer/388/SFGarageDoorStatus.txt" but it doesn't work.
How do I get it work?
…
you just did it again
you dont have to give us all that!!!
Just /SFGarageDoorStatus.txt
means the same thing!
Posted 09 October 2012 - 12:00 PM
I just read your post as "the code is where the code is".
Is the code in your /saves/[you world name]/computer/[your computer id]?
I'm using a multiplayer server, might this be the problem?
Path for code: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfallsave.lua
Path for file: H:HurrdurrGamesMCTekkit_Server_3.1.2modsComputerCraftluaromprogramscomputerNightfalllol.txt
Future notice,
when someone asks for the path.. they mean in CC, not on your literal computer… thank you Mr. Hurrdurr
Yeah I had no clue what to name my hdd…
The file im trying to write to now is at path: H:/Hurrdurr/Games/MC/Tekkit_Server_3.1.2/RandomStuff/computer/388/SFGarageDoorStatus.txt
– RandomStuff is the name of the world map. I've tried that path and "RandomStuff/computer/388/SFGarageDoorStatus.txt" but it doesn't work.
How do I get it work?
…
you just did it again
you dont have to give us all that!!!
Just /SFGarageDoorStatus.txt
means the same thing!
I tried that too, it didn't work