Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


CE-LUA, Write/Edit specific Line of a File

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
cody11102
Newbie cheater
Reputation: 1

Joined: 03 Sep 2017
Posts: 12

PostPosted: Mon Sep 18, 2017 6:02 pm    Post subject: CE-LUA, Write/Edit specific Line of a File Reply with quote

I need a little help.
Im trying to learn how to write/edit a whole Line of a File without changing anything else.
Language: LUA Engine(CE)

Lets say my File is located to 'c:/test.txt' and looks like this:

Code:
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText


... now i want to write to Line '6' and edit/replace the whole Line:

Code:
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText
Changed
RandomText, RandomText
RandomText, RandomText
RandomText, RandomText



Does someone has an example for this?
Back to top
View user's profile Send private message
ParkourPenguin
Grandmaster Cheater Supreme
Reputation: 54

Joined: 06 Jul 2014
Posts: 1815
Location: Arcadian Suburbia

PostPosted: Mon Sep 18, 2017 6:35 pm    Post subject: Reply with quote

Code:
local line = 1
local output = {}
for s in io.lines('C:\\foo.txt') do
  if line == 6 then
    output[#output+1] = 'Changed'
  else
    output[#output+1] = s
  end
  line = line + 1
end

local f = assert(io.open('C:\\foo.txt','w'))
f:write(table.concat(output, '\n'))
f:close()

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
cody11102
Newbie cheater
Reputation: 1

Joined: 03 Sep 2017
Posts: 12

PostPosted: Mon Sep 18, 2017 8:30 pm    Post subject: Reply with quote

Works perfectly, thank you very much!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites