[solved] troubles playing sounds

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
User avatar
Nephilim
Prole
Posts: 9
Joined: Tue Feb 16, 2010 3:00 pm
Location: Netherlands

[solved] troubles playing sounds

Post by Nephilim »

Hi guys,

I'm having a little trouble with playing sounds and I hope you can help me out. The following works fine:

Code: Select all

saythisnumber = love.audio.newSource("audio/0.mp3", "static")
love.audio.play(saythisnumber)
But this piece of code

Code: Select all

if numbertosay == 0 then saythisnumber = love.audio.newSource("audio/0.mp3", "static") end
love.audio.play(saythisnumber)	
generates the following error:
"Incorrect parameter type: expected userdata."
What I was actually *trying* to do, but generates the exact same error, is:

Code: Select all

	Now = os.date('*t') --get the date/time
	
        hour = tostring(Now.hour) -- this works, assigns value XX to 'hour'
	minutes = tostring(Now.min)
	seconds = tostring(Now.sec)

	sayhour = ("snd" .. hour) -- this works, generates a string that contains "sndXX"
	sayminutes = ("snd" .. minutes)
	sayseconds = ("snd" .. seconds)

love.audio.play(sayhour)
(Ofcourse I did sndXX = love.audio.newSource("audio/XX.mp3", "static") somewhere in the code above.

What am I doing wrong? Any help would be greatly appreciated!
Last edited by Nephilim on Mon Feb 22, 2010 8:44 pm, edited 1 time in total.
Programming is an art form that fights back.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: troubles playing sounds

Post by Robin »

You can't play a string:

"hello" is not the same as hello.

You have snd00 = <blah> somewhere?

I actually suggest you use a table:

Code: Select all

snd = {}
snd["00"] = <blah>
Makes everything easier.

You then do:

Code: Select all

love.audio.play(snd[sayhour])
Help us help you: attach a .love.
User avatar
Nephilim
Prole
Posts: 9
Joined: Tue Feb 16, 2010 3:00 pm
Location: Netherlands

Re: troubles playing sounds

Post by Nephilim »

Thanks a lot! I'll try that. Ofcourse I kinda figured the strings were the problem, but I couldn't for the life of me figure out how to solve it another way, except for using a million if's.

Thanks again.
Programming is an art form that fights back.
User avatar
Nephilim
Prole
Posts: 9
Joined: Tue Feb 16, 2010 3:00 pm
Location: Netherlands

Re: troubles playing sounds

Post by Nephilim »

It worked! Yay! Thanks loads.
Programming is an art form that fights back.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests