-SOLVED- Quick Audio Question

I’m trying to add a sound to my game that’s located in the “audio” folder but I’m failing…

[lua]coinSound = audio.loadSound(“game_collectcoin.mp3”, “audio/”)[/lua]

How is it supposed to be done? [import]uid: 103624 topic_id: 18179 reply_id: 318179[/import]

Just as a heads up, whenever you see base directory in the API’s, it’s not asking for an actual directory name. It’s a reference to to different ROOT areas to begin searching. Here they all are:

  • system.ResourceDirectory (refers to your project folder)

  • system.DocumentsDirectory

  • system.TemporaryDirectory

  • stystem.CachesDirectory (new)

Based on your code, I’m assuming your audio asset is in a sub-directory called “audio” in your project folder, so you’d instead use:

local coinSound = audio.loadSound("audio/game_collectcoin.mp3", system.ResourceDirectory )[/code]But since system.ResourceDirectory is the default for that function, you'd only need the first argument.Hope that helps! [import]uid: 52430 topic_id: 18179 reply_id: 69493[/import]

I did what you said, but I failed somewhere else. :confused:

[lua]Windows simulator build date: Jul 27 2011 @ 06:45:53
Copyright © 2009-2011 A n s c a , I n c .
Version: 2.0.0
Build: 2011.591
Runtime error
…rs\Kyle\Documents\Coding\Corona\Makin’ Bank\main.lua:46: attempt to i
ndex global ‘coinSound’ (a userdata value)
stack traceback:
[C]: ?
…rs\Kyle\Documents\Coding\Corona\Makin’ Bank\main.lua:46: in function
<…rs>
[lua]display.setStatusBar(display.HiddenStatusBar)
– local storyboard = require "storyboard"
require (“sprite”)
require(“physics”)

function loadGame()
createPhysics()
createScene()
createPiggyBank()
createButtons()
displayScore()
end

function createPhysics()
physics.start()
physics.setGravity(0, 9.8)
end

function createScene()
local background = display.newImage(“images/game_background.png”, 0, 0)
local ground = display.newImage(“images/game_ground.png”, 0, 445)
physics.addBody(ground, “static”)
– gameSound = audio.loadStream(“audio/game_background.mp3”)
coinSound = audio.loadSound(“audio/game_collectcoin.mp3”)
function ground:collision(event)
event.other:removeSelf()
end
ground:addEventListener(“collision”, ground)
end

function createPiggyBank()
local piggyBankSheet = sprite.newSpriteSheet(“images/game_piggybank.png”, 96, 96)
local piggyBankSet = sprite.newSpriteSet(piggyBankSheet, 1, 6)
sprite.add (piggyBankSet, “pigmleft”, 1, 3, 250, 0)
sprite.add (piggyBankSet, “pigmright”, 4, 3, 250, 0)
piggyBank = sprite.newSprite(piggyBankSet)
physics.addBody(piggyBank, “static”)
piggyBank.x = display.contentWidth / 2
piggyBank.y = 397
function piggyBank:collision(event)
if(event.other.type == “coinbronze”) then
scorePlaceThree = scorePlaceThree + 1
coinSound.play()
elseif(event.other.type == “coinsilver”) then
scorePlaceThree = scorePlaceThree + 5
coinSound.play()
elseif(event.other.type == “coingold”) then
scorePlaceTwo = scorePlaceTwo + 1
coinSound.play()
elseif(event.other.type == “rock”) then

end
event.other:removeSelf()
end
piggyBank:addEventListener(“collision”, piggyBank)
end[/lua] [import]uid: 103624 topic_id: 18179 reply_id: 69502[/import] </…rs>

Nevermind! I got rid of the errors after checking the API references. Man, those things help! [import]uid: 103624 topic_id: 18179 reply_id: 69505[/import]