channelplaying help

BlitzMax Forums/BlitzMax Beginners Area/channelplaying help

B(Posted 2010) [#1]
hey guys I am trying to play a laser sound when you press the spacebar
however to not have the sound play a million times as im using the keydown(key_space) command.

I am trying to use this code but it says attempt to access null field.

btw i am using superstrict

here is my the sound part of my code:

Global channel:TChannel
Global laser:TSound = LoadSound("L1.wav")


If KeyDown(key_space)
	If ChannelPlaying(channel) = 0
		channel = PlaySound (laser)
	EndIf
endif


i am not sure if i am using it right or not.

any help would be greatly appreciated.

Thanks again!

B


Volker(Posted 2010) [#2]
This code should work.
Add a test if the soundfile is loaded:
Global laser:TSound = LoadSound("L1.wav")
if laser=NULL then throw("Can't load sound")



TaskMaster(Posted 2010) [#3]
You need to create the TChannel. You have declared it, but you have not actually created it yet.


B(Posted 2010) [#4]
@TaskMaster
using the cue:tchannel command?

EDIT:
ok I got it working by using:

channel = AllocChannel()


ps - you can download my space game which i am working on right now using the link in my sig however it is only for mac now.


B(Posted 2010) [#5]
DELETED POST