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 


Lua I/O question No.2: specific line index?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Apr 15, 2016 6:20 pm    Post subject: Lua I/O question No.2: specific line index? Reply with quote

Is there a way to get the specific line index? or something can return the line index that shows at which line the program is. For example, I want to read the third line in a txt file, is there a function for that?
Thanks in advance.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Fri Apr 15, 2016 8:35 pm    Post subject: Reply with quote

Code:
local file = io.open("myfile.txt", "r")
local option = {}
for line in file:lines() do
  table.insert(option, line)
end

Code:
print(option[3])
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Sat Apr 16, 2016 1:50 am    Post subject: Reply with quote

Alternatively use a stringlist, load the textfile and then get line 2
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Sat Apr 16, 2016 5:26 am    Post subject: Reply with quote

Zanzer wrote:
Code:
local file = io.open("myfile.txt", "r")
local option = {}
for line in file:lines() do
  table.insert(option, line)
end

Code:
print(option[3])


Or this (because the 3rd line isn't too far from the beginning):
Code:

local file = io.open('myfile.txt','r');
local content = file:read'a'; -- read all the content of file
print(s:match'^.-\n.-\n([^\n]+)'); -- that is, skip first and second line, and print the 3rd one.
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Sat Apr 16, 2016 1:15 pm    Post subject: Reply with quote

Sorry for the late reply, guys. Thanks a lot for all the help. Very Happy
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