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

Editing in a program [lua] [help]

Started by JustInCase, 07 November 2012 - 05:12 AM
JustInCase #1
Posted 07 November 2012 - 06:12 AM
Hi, I was wondering if i could make a program that could edit files within itself, and save those files. like.. microsoft word type thing, You could make a file, type some words, save the files, and view them later. How could i do that?
kazagistar #2
Posted 07 November 2012 - 06:15 AM
How would this be different from edit?
Leo Verto #3
Posted 07 November 2012 - 06:19 AM
copy rom/programs/edit to somewhere else and edit it.
ardera #4
Posted 07 November 2012 - 07:24 AM
Look in the wiki for the fs API.
JustInCase #5
Posted 07 November 2012 - 08:12 AM
How would this be different from edit?

I suppose it wouldn't be…
diegodan1893 #6
Posted 07 November 2012 - 10:16 AM
Just do something like:

--Write a file
hWrite = fs.open("fileName","w")
text = io.read()
hWrite.write(text)
hWrite.close() --This line is very important

-Read a file
hRead = fs.open("fileName","r")
text = hWrite.readLine()
hWrite.close() --It won't work if you don't close the file.
print(text)

This is the basic concept. If you want to know more, check the fs API in the wiki.
JustInCase #7
Posted 07 November 2012 - 01:34 PM
Just do something like:

--Write a file
hWrite = fs.open("fileName","w")
text = io.read()
hWrite.write(text)
hWrite.close() --This line is very important

-Read a file
hRead = fs.open("fileName","r")
text = hWrite.readLine()
hWrite.close() --It won't work if you don't close the file.
print(text)

This is the basic concept. If you want to know more, check the fs API in the wiki.

Alright, Thanks!