| View previous topic :: View next topic |
| Author |
Message |
wekilledbambi03
Joined: 15 Oct 2005 Posts: 31
|
Posted: Sun Dec 11, 2005 3:52 am Post subject: loading multi line .txt |
|
|
| 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? |
|
| Back to top |
|
 |
wekilledbambi03
Joined: 15 Oct 2005 Posts: 31
|
Posted: Sun Dec 11, 2005 10:06 am Post subject: |
|
|
| 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. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Dec 11, 2005 10:29 am Post subject: |
|
|
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: |
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: |
file = io.open("yourfile.txt, "r")
if file then
text = file:read("*a")
-- do something with "text"
file:close()
end
|
|
|
| Back to top |
|
 |
|