Help with audio

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
zine92
Prole
Posts: 6
Joined: Wed Mar 17, 2010 4:33 am

Help with audio

Post by zine92 » Wed Mar 17, 2010 4:39 am

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.
Attachments
pongZ.love
(8.98 KiB) Downloaded 78 times

User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

Re: Help with audio

Post by bmelts » Wed Mar 17, 2010 4:45 am

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.

zine92
Prole
Posts: 6
Joined: Wed Mar 17, 2010 4:33 am

Re: Help with audio

Post by zine92 » Wed Mar 17, 2010 4:59 am

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.
Attachments
pongZ.love
Original PongZ
(36.17 KiB) Downloaded 86 times

User avatar
kikito
Inner party member
Posts: 3152
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Help with audio

Post by kikito » Wed Mar 17, 2010 8:45 am

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.
When I write def I mean function.

zine92
Prole
Posts: 6
Joined: Wed Mar 17, 2010 4:33 am

Re: Help with audio

Post by zine92 » Wed Mar 17, 2010 12:11 pm

thanks. it works. guess i must had accidentally disabled the audio. thanks so much.

Post Reply

Who is online

Users browsing this forum: Exabot [Bot], Majestic-12 [Bot] and 13 guests