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

Write to specific line

Started by ComputerCraftFan11, 06 April 2012 - 06:42 PM
ComputerCraftFan11 #1
Posted 06 April 2012 - 08:42 PM
How can I do:

file:write("public static final Block Block"..blockclass.." = new Block"..blockclass.."("..blockid..", 0)")
To a specific line (line 6)

Then search for

public void load()
{

And write this inside



ModLoader.registerBlock(Block" ..blockclass.. ");
ModLoader.addName(Block" ..blockclass.. ", ""..blockclass.."");
Wolvan #2
Posted 07 April 2012 - 01:21 AM
You mean in a file? Or on a screen? I think you have to put it all in 1 variable and then write the whole variable to the file at the same time
virtualayu #3
Posted 08 April 2012 - 03:35 AM
i think you'll have open the file in write mode then read line by line until you reach the lineyou want then write your line… maybe i'm wrong i'd never tested to read a line in write mode… ^^

And i think it's not possible to search in a file… again maybe i'm wrong ^^ maybe you can read each line and test them to see if it's the right one …
but i never use the file:write thing… i use only the fs api and i learn it recently so i'm not sur about what i'm saying XD…
Wolvan #4
Posted 08 April 2012 - 10:17 AM
There is an API for that purpose:
mad's fLib
Luanub #5
Posted 08 April 2012 - 10:24 AM
I've been doing it by capturing the contents of the file in a table. then using table commands to edit the table, and finally updating the file to match the new edited table.
Wolvan #6
Posted 08 April 2012 - 01:04 PM
I've been doing it by capturing the contents of the file in a table. then using table commands to edit the table, and finally updating the file to match the new edited table.
OK Great to hear you managed it
virtualayu #7
Posted 08 April 2012 - 05:03 PM
I've been doing it by capturing the contents of the file in a table. then using table commands to edit the table, and finally updating the file to match the new edited table.
OK Great to hear you managed it
hum… it's not luanub who opened this topic^^ it's ComputerCraft11 and we didn't know if he managed it… ^^
Wolvan #8
Posted 09 April 2012 - 12:07 PM
I've been doing it by capturing the contents of the file in a table. then using table commands to edit the table, and finally updating the file to match the new edited table.
OK Great to hear you managed it
hum… it's not luanub who opened this topic^^ it's ComputerCraft11 and we didn't know if he managed it… ^^
Damn :P/>/>
Luanub #9
Posted 09 April 2012 - 12:32 PM
If he needs it I can share the code I've been working with. Right now I just using it to remove a specific line from the file but it should be easy to modify it to edit the line instead.