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

Is there a way to edit and save printed Text?

Started by 1234tree4321, 03 October 2013 - 06:08 AM
1234tree4321 #1
Posted 03 October 2013 - 08:08 AM
Title : Is there a way to edit and save printed Text?

For example:


local x = io.read()

fs.makeDir("saves")
local file = fs.open("saves/text","w")
file.writeLine(x)
file.close()

shell.run("clear")

file = fs.open("saves/text","r")
local fileData = {}
local line = file.readLine()
repeat
  table.insert(fileData,line)
  line = file.readLine()
until line == nil
file.close()

local x = fileData[1]

print("Text : \n"..x)

Now, how i can edit and save x?
1234tree4321 #2
Posted 03 October 2013 - 08:12 AM
Title : Is there a way to edit and save printed Text?

For example:


local x = io.read()

fs.makeDir("saves")
local file = fs.open("saves/text","w")
file.writeLine(x)
file.close()

shell.run("clear")

file = fs.open("saves/text","r")
local fileData = {}
local line = file.readLine()
repeat
  table.insert(fileData,line)
  line = file.readLine()
until line == nil
file.close()

local x = fileData[1]

print("Text : \n"..x)

Now, how i can edit and save x?
Vilsol #3
Posted 03 October 2013 - 09:08 AM
You just did that with the code you posted, what exactly are you trying to do?
If you are trying to save to a file what is on a screen, you will need to override all display functions and store them in a screen buffer, which then can be serialized and saved to a file.

And by x you mean "saves/text" or as a variable?
If a variable, then just serialize it.
svdragster #4
Posted 03 October 2013 - 01:02 PM
Do you want to save the content on the screen?
1234tree4321 #5
Posted 03 October 2013 - 02:18 PM
I want to edit a string i previously saved.


EDIT :

2nd Example :


x = "I like Turtles"

fs.makeDir("saves")
local file = fs.open("saves/string","w")
file.writeLine(x)
file.close()

write("Your Text : ")

file = fs.open("saves/string","r")
local fileData = {}
local line = file.readLine()
repeat
  table.insert(fileData,line)
  line = file.readLine()
until line == nil
file.close()

saved_x = fileData[1]

write(saved_x)

--[[
And NOW i want to edit "saved_x" via Keyboard.
For Example i want to replace "Turtles" with "Monkeys" and save it again "as saved_x".
]]
Lyqyd #6
Posted 03 October 2013 - 02:42 PM
Threads merged.