Not that I know of, you'll want to keep another table to tell you that. See what I did below:
Code: Select all
function love.load()
sources = {
love.audio.newSource("harmoney.mp3"),
love.audio.newSource("ghosts-n-stuff.mp3")
}
selections = {
true,
true
}
for i=1, #sources do
sources[i]:setVolume(1.0)
sources[i]:setLooping(true)
love.audio.play(sources[i])
end
end
function love.draw()
for i=1, #sources do
local text = "Source "..i.." is playing"
if not selections[i] then
text = "Source "..i.." is not playing"
end
love.graphics.print(text, 8, 32 * i)
end
end
function love.keypressed(key, unicode)
if key == 'p' then
for i=1, #sources do
pauseSource(i)
end
end
if key == 'r' then
for i=1, #sources do
resumeSource(i)
end
end
if key == '1' or key == '2' then
local keyNumber = tonumber(key)
if selections[keyNumber] then
pauseSource(keyNumber)
else
resumeSource(keyNumber)
end
end
end
function pauseSource(which)
sources[which]:pause()
selections[which] = false
end
function resumeSource(which)
sources[which]:resume()
selections[which] = true
end
Several things to get from this. One, you can have tables which parallel to each other, so you can reuse key values. Two, it became a good idea to define some functions to do the pausing and resuming. Three, tonumber() is awesome. And four, having a draw function to show us what is happening is also awesome.
If you have any questions about the above code, please ask (what are locals, why does #sources work, etc). I'm not sure how much you know and I don't want to step on any toes, or just hand you solutions that work and you don't know how.