Jump to content




Write to specific line


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

#1 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 06 April 2012 - 07: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.."");


#2 Wolvan

  • New Members
  • 384 posts
  • LocationIn the TARDIS

Posted 07 April 2012 - 12: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

#3 virtualayu

  • New Members
  • 31 posts

Posted 08 April 2012 - 02: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...

#4 Wolvan

  • New Members
  • 384 posts
  • LocationIn the TARDIS

Posted 08 April 2012 - 09:17 AM

There is an API for that purpose:
mad's fLib

#5 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 08 April 2012 - 09: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.

#6 Wolvan

  • New Members
  • 384 posts
  • LocationIn the TARDIS

Posted 08 April 2012 - 12:04 PM

View Postluanub, on 08 April 2012 - 09:24 AM, said:

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

#7 virtualayu

  • New Members
  • 31 posts

Posted 08 April 2012 - 04:03 PM

View PostWolvan, on 08 April 2012 - 12:04 PM, said:

View Postluanub, on 08 April 2012 - 09:24 AM, said:

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

#8 Wolvan

  • New Members
  • 384 posts
  • LocationIn the TARDIS

Posted 09 April 2012 - 11:07 AM

View Postvirtualayu, on 08 April 2012 - 04:03 PM, said:

View PostWolvan, on 08 April 2012 - 12:04 PM, said:

View Postluanub, on 08 April 2012 - 09:24 AM, said:

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

#9 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 09 April 2012 - 11:32 AM

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users