LÖVE 0.6.1

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: LÖVE 0.6.1

Post 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. :(
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: LÖVE 0.6.1

Post by bmelts »

love.filesystem.load("file.lua")()
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: LÖVE 0.6.1

Post by Jasoco »

Yeah, but it doesn't run the file when I do that. I need it to run the code immediately.
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: LÖVE 0.6.1

Post 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.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: LÖVE 0.6.1

Post 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. :ultrahappy:
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: LÖVE 0.6.1

Post 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?
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: LÖVE 0.6.1

Post 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?
User avatar
hatingcollege
Prole
Posts: 2
Joined: Tue Mar 02, 2010 4:47 am
Location: Virginia, USA
Contact:

Re: LÖVE 0.6.1

Post 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
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: LÖVE 0.6.1

Post 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.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: LÖVE 0.6.1

Post by kikito »

Mmm

I hit the same problem last night. Let me open a feature request ticket for you!
When I write def I mean function.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests