channelstop not working
Blitz3D Forums/Blitz3D Beginners Area/channelstop not working
| ||
In my code, I have a menu screen and the actual game. I want different music for both of them, but can't get the menu music to stop when the game music begins. The game music is layered over the menu music.Global sound Global soundplaying this is at the beginning of the code sound = LoadSound("Joes Last Mix.mp3") LoopSound sound soundplaying = PlaySound (sound) this is used to load menu music StopChannel soundplaying soundplaying = 0 FreeSound sound sound = 0 this is used when I exit the menu to go to the game sound = LoadSound("Joes Last Mix digitalized fast.mp3") LoopSound sound soundplaying = PlaySound (sound) this is used to load the new music for the game StopChannel (soundplaying) soundplaying = 0 FreeSound (sound) sound = 0 this is used to stop the sound before returning to the menu after exiting the game. Every time I switch between the menu and the game it adds another sound on top of the others. I am confused about this. |
| ||
Hard to say. I don't see anything wrong with your code. Are you certain the commands are called in the order you've shown them? Have you tried stepping through your program with debug mode? |
| ||
They are all called in that order, however they are all in different functions, and the code for the menu is in a seperate included file. The globals are declared in this file (at beginning) |
| ||
Is it possible the values of sound and/or soundplaying are getting changed somewhere other than where they're supposed to? This would cause the problem you are having. To investigate, put in some DebugLog commands in all of the above places to say where you are and what the values of those two variables are. If one or both of them change between starting a tune and stopping it, another part of your program is changing them when it shouldn't. For example... sound = LoadSound("Joes Last Mix.mp3") LoopSound sound soundplaying = PlaySound (sound) DebugLog "Started menu music, sound: "+sound+" channel: "+soundplaying |
| ||
thanks for the suggestion, JazzieB. I tried what you suggested and came up with the soundplaying not being set to the channel. It remains zero on all 4 of the logs I put in. I also relized that I start the music twice at almost the same time when I change the screen resolution again. Does anyone know why the channel is not being set?started menu music, sound: 11598352 channel: 0 started menu music, sound: 11599680 channel: 0 before stopped menu music, sound: 11599680 channel: 0 after stopped menu music, sound: 0 channel: 0 |
| ||
I found a bug that when starting menu music it doesn't set the channel. After fixing it, the channel is still lost when I go to stop the channel.before started menu music, sound: 0 channel: 0 started menu music, sound: 11598352 channel: 11599520 before stopped menu music change graphics, sound: 11598352 channel: 0 after stopped menu music change graphics, sound: 0 channel: 0 before started menu music, sound: 0 channel: 0 started menu music, sound: 11598352 channel: 11599280 before stopped menu music, sound: 11598352 channel: 0 after stopped menu music, sound: 0 channel: 0 |