Page 3 of 5
Re: LÖVE 0.6.1
Posted: Mon Mar 01, 2010 5:28 am
by Jasoco
What is the 0.6.1 equivalent to love.filesystem.include()? I used it to load and run files at runtime. Now it doesn't work.
I mean there's love.filesystem.load() but that only loads a file.
require() only requires a file once. Whatever happened to include? How do I load a file at will during my game and run it with the ability to run it more than once? I used love.filesystem.include() to load my scripts and maps. Now I can't.
Re: LÖVE 0.6.1
Posted: Mon Mar 01, 2010 5:42 am
by bmelts
love.filesystem.load("file.lua")()
Re: LÖVE 0.6.1
Posted: Mon Mar 01, 2010 5:43 am
by Jasoco
Yeah, but it doesn't run the file when I do that. I need it to run the code immediately.
Re: LÖVE 0.6.1
Posted: Mon Mar 01, 2010 5:44 am
by bmelts
See: the parentheses at the end.
love.filesystem.load returns a function that, when executed, runs the code in the file. Calling that function runs the file. Putting the parentheses after love.filesystem.load("file.lua") runs the loaded file immediately.
Re: LÖVE 0.6.1
Posted: Mon Mar 01, 2010 5:46 am
by Jasoco
Oh, for the love of. So that's what the perinthesis are for? I just tried that and it worked. Wow. Thanks!
I'm working on getting my project converted over to 0.6.1 by using a test project to figure out all the syntax's for the changed stuff. I just figured out how to do Quads and audio. Now loading files. I'm well on my way.
Re: LÖVE 0.6.1
Posted: Tue Mar 02, 2010 5:16 am
by Jasoco
Question about audio. How do I play the same sound effect more than once at a time? For instance, explosions going off. I'd want them overlaping. But it doesn't seem to let me play the same thing twice if it's already playing. Am I doing it wrong?
Re: LÖVE 0.6.1
Posted: Tue Mar 02, 2010 5:51 am
by bmelts
Yeah, a single Source can't play itself again while it's already playing. It's just one Source, after all.
There's a few ways you can work around it. You can create multiple Sources from the same file (don't forget to use "static" mode) - assuming it's a small file, it won't take up that much space in memory, and enables you to play the same sound multiple times at once. You'd need to write some code to handle when it should use which Sources (or even create Sources on the fly if you don't want to limit yourself, though I don't know about how fast that would be), but it's doable.
Other than that, uh, I dunno. Anyone else have suggestions?
Re: LÖVE 0.6.1
Posted: Tue Mar 02, 2010 6:43 am
by hatingcollege
Disclaimer: I'm a LOVE (and Lua) noob, so.. get your grain of salt ready..
The way I handle this in other game libraries is, as anjo mentioned, create multiple sources from the same file.
You can use a basic queue system to ensure the "freshest" (as in "most likely to have finished playing") source will be played next.
Something like this:
Code: Select all
SoundQueue = {}
function SoundQueue:new(src, type, length)
local this = {}
local sources = {}
local index = 1
for i = 1, length, 1 do
table.insert(sources, love.audio.newSource(src, type))
end
function this:play()
if (#sources == 0) then
return
end
if (index > #sources) then
index = 1
end
love.audio.stop(sources[index])
love.audio.play(sources[index])
index = index + 1
end
return this
end
function love.load()
queue = SoundQueue:new('fire.wav', 'static', 10)
end
(function()
local timer = 0
function love.update(dt)
timer = timer + dt
-- play the sound every 100 milliseconds
while (timer >= .1) do
timer = timer - .1
queue:play()
end
end
end)()
I'm using 10 sources in this example. I suggest you try to limit yourself to 16, if possible. I have seen some environments where OpenAL reports that 32, 64, etc .. simultaneous channels are available, but I have never seen one report less than 16 channels.
-- Matt
Re: LÖVE 0.6.1
Posted: Tue Mar 02, 2010 7:24 am
by Jasoco
Welcome to the forum, Matt. I'll have to try out your code tomorrow when I get a chance.
Is there a reason the creators couldn't bring back the ability to play the same sound again even if it's still playing? Maybe some special mode or something?
The only times I really need the same sound playing multiple times, well, there's a lot actually. Text being written. Thunder crashing twice in succession. Bombs going off one after another. Rapid firing of arrows. More than one enemy firing a weapon at once. It seems to me this should really be brought back in some form. Sources are great, but we need a way to layer the sounds.
Re: LÖVE 0.6.1
Posted: Tue Mar 02, 2010 12:54 pm
by kikito