old code new update ?

Blitz3D Forums/Blitz3D Programming/old code new update ?

Paul "Taiphoz"(Posted 2007) [#1]
Hay all. Its been a while since I last coded anything in blitz, but during that time I have kept upto date with all updates, not read any of the notes just downloaded them and installed to make sure I was current.

Anyway, long story short I have hit a problem where there wasnt one before.

here is some code.

		If u\life=<0
			FreeSound u\ping
			FreeEntity u\glow
			FreeEntity u\model
			Delete u	
		End If


The type U, is a powerup in the game, the field ping is assigned a channel as follows during the Update phase of all Powerup objects.

I then do a check as I scan them all, if any are mines I check to see if the mine sound is playing, and if not I play it with a channel.

		If u\ptype=pmine
			If ChannelPlaying(u\ping)=False
				u\ping=PlaySound(sonar_snd)
			End If
		End If


This is now giving me an error, not all powerups have a sound in fact only the mines do at the moment, as a warning to let you know they are activated and about to blow.

When a mine blows, the game crashes with a "Sound does not exist".

I am guessing, that something in the last 3 or 4 years was changed with the sounds system, If I am assigning a sound to a field in a type called ping with playsound, how do I free it up once the U object is deleted.


Paul "Taiphoz"(Posted 2007) [#2]
Fixed the code box DOH!..


LAB[au](Posted 2007) [#3]
It crashes where? When freeing the type instance or when playing the sound?


GfK(Posted 2007) [#4]
I'm confused.

You say u\ping is a channel, yet you're using FreeSound on it in the first bit of code?


Paul "Taiphoz"(Posted 2007) [#5]
I apologise, the top bit of code comes later on in the file I just happend to post it first.

And yes it crashs when trying to free the sound being free-ed from the channel.

Like I said this code is 3 or 4 years old, and used to work fine but I guess during all those updates to B3D something has changed.

Do we need to free channels ? or is it done automatically as soon as the sound is finished playing ?

I'm about as rusty as they come, havnt touched any code in 3 or 4 years so it may be something really silly.


GfK(Posted 2007) [#6]
Playing a sound doesn't create a new instance of it.

If you free the sound once, then its gone - even if you have a hundred pointers to the sound. Hence the 'sound does not exist' error.

Stop/free the channel but leave the sound where it is until you've completely done with it.


Paul "Taiphoz"(Posted 2007) [#7]
is there a new set of commands to free a channel, or do you mean that if you use stop on the channel, that indeed free's it ?

Thanks for the help by the way, part of the reason iv taken so long to get back to coding was the thought of having to relearn a lot of stuff and ask a lot of stupid questions all over again.


GfK(Posted 2007) [#8]
Yeah just use StopChannel. You can also use channel = 0 after stopping a channel, just as a bit of housekeeping.