Trying to Add Sound to Diddy Sound Example - Error

Monkey Forums/Monkey Programming/Trying to Add Sound to Diddy Sound Example - Error

c.k.(Posted 2011) [#1]
I'm trying to understand sounds using Monkey+Diddy. When I attempt to add a sound to the GUI example, I get this error:



I've added four lines to the GUI example and have added the sounds/drum.wav file in testGUI.data.

Here's the code (only showing parts I changed):

Class MyGame extends DiddyApp
	Method OnCreate:Int()
		Super.OnCreate()
		images.Load("button.png", "", False)
		images.Load("buttonClick.png", "", False)
		images.Load("check.png", "", False)
		images.Load("checkClick.png", "", False)
		sounds.Load("drum.wav") ' load the sound
		drawFPSOn = True
		guiScreen = new GUIScreen
		guiScreen.PreStart()
		return 0
	End
End

Class MyGUI Extends GUI
	Field button:Button
	Field toggleButton:Button
	Field slider:Slider
	Field buttonImage:GameImage
	Field drum:GameSound ' define the variable for the sound
	
	Method New()
		drum = game.sounds.Find("drum") ' get the sound
		
		button = New Button(desktop, game.images.Find("button"), game.images.Find("buttonClick"))
		button.SetBounds(150,50,100,50)
		button.Text ("HELLO", 0.5, 0.5)
		
		toggleButton = New Button(desktop, game.images.Find("check"))
		toggleButton.toggle = True
		toggleButton.SetBounds(50,120,100,50)
		toggleButton.StyleSelected.image = game.images.Find("checkClick")
		toggleButton.StyleSelected.drawBackground = False
		
		slider = New Slider(desktop)
		slider.SetBounds(50,190,200,20)
		slider.ShowButtons = True
		slider.StyleNormal.red = 0
		slider.StyleNormal.green = 0
		slider.StyleNormal.blue = 255
		
	End
	
	Method ActionPerformed:Void(source:Component, action:String)
		If source = slider And action = ACTION_VALUE_CHANGED Then
			Print "slider="+Slider(source).value
		ElseIf source = button And action = ACTION_CLICKED Then
			Print("pressed button!")
			drum.Play() ' play sound when button clicked
		ElseIf source = toggleButton And action = ACTION_CLICKED Then
			If toggleButton.selected Then
				Print("pressed toggleButton! selected=true")
			Else
				Print("pressed toggleButton! selected=false")
			End
		End
	End
End


If I comment out the drum.Play() line, no error occurs. So I figure everything's loaded up fine, it just can't play it from there.


Dima(Posted 2011) [#2]
On the contrary, seems the sound isn't loading correctly. Try loading "sounds/drum.wav" if the file is inside a subfolder, thats how it would be normally, don't have experience with diddy though.

Edit: think i rushed with the reply, you're getting a compile error not runtime, so not sure.


therevills(Posted 2011) [#3]
Slight bug in Diddy, if you alter the collections.monkey file and change the Emumerator near line 723 to look like this:

	Method Enumerator:AbstractEnumerator<IntObject>()
		Return New IntListEnumerator(Self)
	End


It should work, I need to talk to Samah about this one so I'm not committing this change yet... (since he coded the collections stuff :P)


c.k.(Posted 2011) [#4]
Woo hoo! Works!

Thanks, therevills!


Samah(Posted 2011) [#5]
Fixed.