Jump to content




[LUA][Help] writing text to a file


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

#1 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 07 October 2012 - 11:20 PM

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...

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


#2 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 07 October 2012 - 11:32 PM

The /rom/ directory is restricted from editing by programs.

#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 October 2012 - 11:42 PM

This fact was even mentioned in your previous topic asking a similar question:

View PostLyqyd, on 07 October 2012 - 09:21 PM, said:

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.


#4 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 07 October 2012 - 11:57 PM

Ah my bad, so where can you write files safely?

#5 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 08 October 2012 - 12:02 AM

The best place to write files is in the same directory as the script that's doing the writing.

#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 08 October 2012 - 12:17 AM

View PostKingdaro, on 08 October 2012 - 12:02 AM, said:

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


#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 08 October 2012 - 12:25 AM

The program isn't in rom either, right?

#8 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 08 October 2012 - 12:36 AM

View PostLyqyd, on 08 October 2012 - 12:25 AM, said:

The program isn't in rom either, right?

Nope, it's only in the exact folder where the code is

#9 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 08 October 2012 - 01: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]?

#10 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 08 October 2012 - 01:59 AM

View PostKingdaro, on 08 October 2012 - 01:40 AM, said:

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

#11 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 08 October 2012 - 04: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.

#12 hego555

  • Members
  • 89 posts

Posted 08 October 2012 - 05:03 AM

View Postsidekick_, on 08 October 2012 - 01:59 AM, said:

View PostKingdaro, on 08 October 2012 - 01:40 AM, said:

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

#13 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 08 October 2012 - 08:55 PM

View Posthego555, on 08 October 2012 - 05:03 AM, said:

View Postsidekick_, on 08 October 2012 - 01:59 AM, said:

View PostKingdaro, on 08 October 2012 - 01:40 AM, said:

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?

#14 hego555

  • Members
  • 89 posts

Posted 08 October 2012 - 11:39 PM

View Postsidekick_, on 08 October 2012 - 08:55 PM, said:

View Posthego555, on 08 October 2012 - 05:03 AM, said:

View Postsidekick_, on 08 October 2012 - 01:59 AM, said:

View PostKingdaro, on 08 October 2012 - 01:40 AM, said:

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!

#15 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 09 October 2012 - 11:00 AM

View Posthego555, on 08 October 2012 - 11:39 PM, said:

View Postsidekick_, on 08 October 2012 - 08:55 PM, said:

View Posthego555, on 08 October 2012 - 05:03 AM, said:

View Postsidekick_, on 08 October 2012 - 01:59 AM, said:

View PostKingdaro, on 08 October 2012 - 01:40 AM, said:

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users