Page 1 of 1

Help with audio

Posted: Wed Mar 17, 2010 4:39 am
by zine92
I am trying to implement sound in my first pong game named pongZ. Anyways, this error always occur when i run my game. An attempt to index 'audio' blah blah blah. Now this is what i added to my main.lua files.

Code: Select all

	-- Sound 1 is when ball hit wall
	hitWallSound = love.audio.newSource("sounds/hitwall.wav")
	-- Sound 2 is when ball hit paddle
	hitPaddleSound = love.audio.newSource("sounds/hitpaddle.wav")
	-- Sound 3 is when new ball is spawned
	newBallSound = love.audio.newSource("sounds/newball.wav")
I try this lines in a seperate .love file and it work but when i put into my own game, there is an error. Here is the pongz.love if anybody wants to take a look. btw, i am new to game dev/design so thank you for taking the time to help me. Thanks.

Re: Help with audio

Posted: Wed Mar 17, 2010 4:45 am
by bmelts
You're declaring a function called love.audio() in main.lua. The problem here is that love.audio already exists, as a table which contains all of LÖVE's audio-related stuff. By redefining it as a function, you're preventing LÖVE from using it the way it expects to, so it gets very confused and (understandably) errors.

There's an easy solution to this - don't put things in the love table.

Re: Help with audio

Posted: Wed Mar 17, 2010 4:59 am
by zine92
oops. what i did previously was declare all in another .lua file and then this error occured that i thought i had to move it somewhere else. anyway thanks.

Edit: i uploaded the original .love file. I am not sure why it isn't loaded as supposed.

Edit2: I got what you were trying to say. Is there an alternative to loading sound other using the love.audio which doesn't work for me.

Re: Help with audio

Posted: Wed Mar 17, 2010 8:45 am
by kikito
Mm maybe this is related with the fact that the sound module is deactivated in your config?

conf.lua:

Code: Select all

	set.modules.joystick = false;
	set.modules.physics = false;
	set.modules.audio = false; -- here
Try removing that line.

Re: Help with audio

Posted: Wed Mar 17, 2010 12:11 pm
by zine92
thanks. it works. guess i must had accidentally disabled the audio. thanks so much.