loading multi line .txt

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

loading multi line .txt

Post by wekilledbambi03 »

i know that there is an example of loading multiple lines in snake. however ive been staring at it and fiddling with it for a while. i just cant get it to work right. can someone explain it in a bit of detail?
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Post by wekilledbambi03 »

nevermind...i went with creating a bunch of .txts just to get it done. but if anyone still wants to answer im sure others (still including me) would be interested.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Note: this is not a general Lua forum and reading the manual at http://www.lua.org/manual/5.0/manual.html and "Programming In Lua" at http://www.lua.org/pil/ would have solved your problem.

But lets take a look at snake, I don't see your problem, this loads already multiple lines:

Code: Select all

file = io.open("yourfile.txt, "r")
if file then
	for line in file:lines() do
		-- do something with "line"
	end
	file:close()
end
If you don't want to process each single file, but want to load the whole file in a string, take a look at http://www.lua.org/pil/21.1.html and write it like this:

Code: Select all

file = io.open("yourfile.txt, "r")
if file then
	text = file:read("*a")
	-- do something with "text"
	file:close()
end
Post Reply