I got it working, but I don't want it to loop. Can I have it open and not loop?Wojak wrote:this is working on my PC:Code: Select all
if songFile and love.filesystem.exists(love.filesystem.getSaveDirectory( ).."/"..songFile) then songMusic = love.audio.newSource(songFile, "stream") end
How to save entire contents of a table to a text file?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: How to save entire contents of a table to a text file?
Re: How to save entire contents of a table to a text file?
You are talking about the sound?
If yes then:
https://love2d.org/wiki/Source
If yes then:
Code: Select all
songMusic:setLooping( false )
Re: How to save entire contents of a table to a text file?
How could I have missed that?!Wojak wrote:You are talking about the sound?
If yes then:https://love2d.org/wiki/SourceCode: Select all
songMusic:setLooping( false )
EDIT: I would like to know if there's a function that returns the length of a source. I couldn't find it on the Wiki.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: How to save entire contents of a table to a text file?
What I don't get is why ending with a comma doesn't work. It should and does work on my machine.
Using #t doesn't work here because
Then call print(write_table({a=1, b=2, c=3})), it should print {a=1, b=2, c=3}.
The order is arbitrary, that is because it is a hash table, which means keys are no stored in any order you would expect, but instead stored in a way that makes it fast to retrieve items from the table.
Using #t doesn't work here because
- you are comparing it to values, instead of indexes.
- you only have string keys, which means #t is always 0.
Code: Select all
write_table = function (t)
local s = "{"
local first = true
for k,v in pairs(t) do
if first then
first = false
else
s = s .. ", "
end
s = s .. k .. " = " .. v
end
s = s .. "}"
return s
end
The order is arbitrary, that is because it is a hash table, which means keys are no stored in any order you would expect, but instead stored in a way that makes it fast to retrieve items from the table.
Help us help you: attach a .love.
Re: How to save entire contents of a table to a text file?
Thanks, I didn't realize, but I don't really think that I need the order to be right in this program. I replaced the write_table function though.Robin wrote:What I don't get is why ending with a comma doesn't work. It should and does work on my machine.
Using #t doesn't work here becauseThis is a better solution if you really don't want terminating commas:
- you are comparing it to values, instead of indexes.
- you only have string keys, which means #t is always 0.
Then call print(write_table({a=1, b=2, c=3})), it should print {a=1, b=2, c=3}.Code: Select all
write_table = function (t) local s = "{" local first = true for k,v in pairs(t) do if first then first = false else s = s .. ", " end s = s .. k .. " = " .. v end s = s .. "}" return s end
The order is arbitrary, that is because it is a hash table, which means keys are no stored in any order you would expect, but instead stored in a way that makes it fast to retrieve items from the table.
Who is online
Users browsing this forum: Google [Bot] and 1 guest