I went to the wiki to learn how to read a file line by line, but I came across this:
iterator = File:lines()
returns function(?) iterator
I'm sitting here confused wondering what the heck this means. How would you go through all the lines in the file using this err...function? I've never really worked with functions that return functions, so help would be appreciated, thanks.
How to use (file):lines()?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: How to use (file):lines()?
Code: Select all
for line in file:lines() do
print(line)
end
Re: How to use (file):lines()?
If there was a rep system, I'd rep you. Thank you!bartbes wrote:prints all lines in the file file.Code: Select all
for line in file:lines() do print(line) end
But how do I make it so it only does it ONCE? It keeps doing it over and over >.<
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to use (file):lines()?
Don't put it in love.update(), but put it in love.load().Kingdaro wrote:But how do I make it so it only does it ONCE? It keeps doing it over and over >.<
EDIT: love.update() is called once per frame.
Help us help you: attach a .love.
Re: How to use (file):lines()?
I did, technecally, put it in love.load. Here's what I did, in reality.
Code: Select all
function love.load()
file = love.filesystem.newFile("song.txt")
file:open("r")
generate()
end
function generate()
for i in file:lines() do
for v=1, 4 do
if string.sub(i,v,v) == "1" then
body = love.physics.newBody(world,(v-1)*64,0,0,0)
notes[#notes+1] = body
end
end
end
end
Re: How to use (file):lines()?
I send the command once, it fires it repeatedly.Robin wrote:OK, then what is the problem?
EDIT: Never mind, fixed. But how do I make it wait, say half a second, between line readings?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to use (file):lines()?
Then you need to do... well, the easiest way to do that would be to load the file before, and just change a variable each half a second:Kingdaro wrote:EDIT: Never mind, fixed. But how do I make it wait, say half a second, between line readings?
Code: Select all
function love.load()
-- file:lines() -> you put them in table Lines
lineIndex = 0
timeX = 0
end
function love.update(dt)
timeX = timeX + dt
if timeX > .5 then
timeX = 0
lineIndex = lineIndex + 1
end
end
Help us help you: attach a .love.
Who is online
Users browsing this forum: Ahrefs [Bot] and 85 guests