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.

 
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 10:46 am    Post subject: Lua I/O question. Reply with quote

I want to read stuff from a txt file with the name "123".
For example, in 123.txt, the characters are:
Code:

abcd
efgh
ijkl
mnop

To be more specific, there are four lines and each line has 4 characters. If I want to read the third character of each line. How to do that? I only know I may need to use "io.line" combined with "io.read". Sad

Now I use io.read() to read the whole file and then use "string.sub()" to read the third characters of each line by manually counting their position in the file, for example "c = #t +3", "g = #t +8", #t is the length of all the characters. It must be a better way than this.

Thanks in advance.
Back to top
View user's profile Send private message
Redouane
Master Cheater
Reputation: 3

Joined: 05 Sep 2013
Posts: 363
Location: Algeria

PostPosted: Fri Apr 15, 2016 11:23 am    Post subject: Re: Lua I/O question. Reply with quote

fmanager wrote:
I want to read stuff from a txt file with the name "123".
For example, in 123.txt, the characters are:
Code:

abcd
efgh
ijkl
mnop

To be more specific, there are four lines and each line has 4 characters. If I want to read the third character of each line. How to do that? I only know I may need to use "io.line" combined with "io.read". Sad

Now I use io.read() to read the whole file and then use "string.sub()" to read the third characters of each line by manually counting their position in the file, for example "c = #t +3", "g = #t +8", #t is the length of all the characters. It must be a better way than this.

Thanks in advance.


Code:
local file = io.open('123.txt','r');
for line in file:lines() do
    print('third character is '..line:sub(3,3))
end
Back to top
View user's profile Send private message
Dr.Disrespect
Grandmaster Cheater
Reputation: 3

Joined: 17 Feb 2016
Posts: 526

PostPosted: Fri Apr 15, 2016 11:25 am    Post subject: Re: Lua I/O question. Reply with quote

Redouane wrote:
fmanager wrote:
I want to read stuff from a txt file with the name "123".
For example, in 123.txt, the characters are:
Code:

abcd
efgh
ijkl
mnop

To be more specific, there are four lines and each line has 4 characters. If I want to read the third character of each line. How to do that? I only know I may need to use "io.line" combined with "io.read". Sad

Now I use io.read() to read the whole file and then use "string.sub()" to read the third characters of each line by manually counting their position in the file, for example "c = #t +3", "g = #t +8", #t is the length of all the characters. It must be a better way than this.

Thanks in advance.


Code:
local file = io.open('123.txt','r');
for line in file:lines() do
    print('third character is '..line:sub(3,3))
end


Thank you so much, I have been stuck with this issue for a while. 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