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.
-- 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.
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.
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.