Thought for the Dazed

I just made a program that removes entrepreneurs from tv shows. It has a dragon drop user interface.

Flickr
Twitter
Search entire site

XNA Book Discussion > Chapter 7 Error

Hi Rob,

Everything's being going smoothly with the book (3.0 Edition) untill now :(

In the drumpad program I'm getting this error

" Cannot implicitly convert type 'bool' to 'Microsoft.Xna.Framework.Audio.SoundEffectInstance' "

It seems to have a problem with this code


if (musicInstance == null)

{
musicInstance = music.Play();

}

I'm sure my code is the same as yours up to page 122 but I still get this error.

Any help would be much appreciated, and my apologies if this is the wrong place to post this as I couldn't find a better suited spot.

Thanks
October 20, 2009 | Unregistered CommenterDenzil
Hi. Glad it is going well (mostly). The problem is because you are using XNA 3.1 rather than 3.0. This came out just after the book went to print (rather annoyingly) and they changed the way that the sound works. I blogged about it here:

http://www.robmiles.com/journal/2009/7/25/breaking-changes-in-xna-31-soundeffect.html

I'll have a look at the book example and make another blog post which explains how to fix it.
October 21, 2009 | Registered CommenterRob
Thanks for getting back to me, glad to know I wasn't seriously confused about something! I can finally continue ... :)
October 23, 2009 | Unregistered CommenterDenzil
I just got to this chapter and had the same issue. I've only just started programming so I'm not sure if this is the proper way to solved this but I got it to work by doing the following:

if (oldpad1.Buttons.LeftShoulder == ButtonState.Released && pad1.Buttons.LeftShoulder == ButtonState.Pressed)
{
if (musicInstance == null)
{
musicInstance = music.CreateInstance();
musicInstance.IsLooped = true;
musicInstance.Play();
}
else
{
musicInstance.Play();
}
}
January 13, 2011 | Unregistered CommenterJoe
Spot on. Just right. The very first time that you get a play request you have to check to see if you have a SoundEffectInstance to use. If you haven't you need to create one and then play it, otherwise you just have to call play on the existing one.
January 14, 2011 | Registered CommenterRob