My first code ever

Miscellaneous Forums/General Discussion/My first code ever

Hi guys,

Well, Im very happy of myself. And even though it is lame, I still want to share since its done in blitzplus.

I have a cop forum, and we have a kid section. Well, I tried to make an embedded function for the site, but dont know flash etc. So I turned to my Blitzplus. What I have, is a siren console. Since almost all kids love to play with the sirens in a plice car, I made a game (or whatever its called) and want to shows yas all.

So here is my very first all time, code, using blitzplus. Have fun. (please dont laugh LOL)

http://www.mediafire.com/?tmtonmybx1m


-------------------

Direction in playing the sirens:

1) To escape and at anytime, use the ESC key, at the top left of your keyboard. this is the only way to leave.
2) To use "yelp", use key number 1
3) To use "airhorn", use key number 2
4) To use "wail", use key number 3
5) To use "phaser" use key number 4
6) To use "hi-lo", use key number 5
7) To use "manual", use key number 6 (didnt program, an actuall manual. This is a pre-recorded manual)
To be completly obnoxious to everyone at home, use all the keys at once, and turn up speakers LOL.

I'd have it so if you hit the same key again it turns it off. :P

Not bad for first code. I remember my first game code that I thought actually meant something. It was in DarkBasic and I had a tie fighter flying around the screen. I thought that was the coolest and I'd be rich in about a month...

I thought that was the coolest and I'd be rich in about a month...


Me too, me too, LOL :D Well, it actually wore off after 15 minutes. As far as turning it off, Im in the process of doing that, in "Sirens Version 2" LOL. It was more of a quick put-together, but was more shocked that it ACTUALLY worked LOL. I spent the last 2 days, looking at flash etc, and downloading, this and that, I just decided to stick with blitzplus. :) Thanxs Chroma :D

just had a try
kinda hope you dont have push to off
if so im not overwriting this version
i should have recorded it, it was fun having the same wav playing 3 times then another 3 random buttons following on
:)

LOL, Yup, Im working on that. Real sirens in the cruisers, actually toggle, On/Off. But the wav seemed to finish to the end. Which is something I didnt want. And another thing that drove me nuts, was the fact, if you hit one siren, and went to another, the first still played, till it was done.


The only one that I cant modify (with my level of coding LOL) is the manual. In Cruisers, ambulances and so on, with sirens,when hitiing a manual, the pitch just goes up, and stays up till, you release. Thats something a pre-recorded wav cant do. A perfect example of a manual siren, is in firetrucks (ones with old low tone) Firetrucks dont have a prerecoded or programed siren in the siren box. The second a firefighter, hits the siren, it goes up till he releases the toggle. I must say, those firefighers are siren musicians LOL.

Thanks guys for your imput. I am greatful. Beginers will not know, what to perfect, or where their next goals are, if it wasnt for positive imput. :D

some if key stopsound playsound (or whatever they are called)

myself coming from oddball 'music' i really dig the it keeps on playing even if ive hit key 1 3 times :)
but if you do change it for the better (as an app for the worse as an offencive sound box) at least the wav's are still on my box to muck around with

@ T David, I sent you an e-mail.

Cheers
Stevie

10-4 Thank you :)

Ok, I am in the process, of doing like Chroma said. Or close to it LOL. I could go to another project, but since Im still learning, I might as well continue with this lame one LOL.

Here is the original code to what I gave for a link.

---------------

;;;;;sirenbox by David;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
AppTitle "Sirens" 
Graphics 800,600,24,2

SeedRnd MilliSecs() 

;Load the image.
sirenimage = LoadImage("sirenbox.bmp")
DrawImage sirenimage,20,100

;load the sounds.
yelpsound = LoadSound("audio/yelp1.wav")
airhornsound = LoadSound("audio/air1.wav")
wailsound = LoadSound("audio/wail1.wav")
phasersound = LoadSound("audio/ph1.wav")
hilosound = LoadSound("audio/hilo1.wav")
manualsound = LoadSound("audio/manual.mp3")


;Loop

Repeat 

If KeyHit(2)
          PlaySound yelpsound 

          EndIf  

If KeyHit(3)
          PlaySound airhornsound
EndIf 
If KeyHit(4)
          PlaySound wailsound 

          EndIf 

If KeyHit(5)
          PlaySound phasersound

          EndIf

If KeyHit(6)
          PlaySound hilosound

          EndIf 

If KeyHit(7)
          PlaySound manualsound

          EndIf

 
;ending 
Until KeyHit(1)



-----------------------------------------


Now, I had a friend of mine, AKA Yo Wazup, remodify what I have, and came up with the code, to what I was hoping for. What was I hoping for? I was hoping, like in a real cruiser, you hit what ever siren you wanted (lets take wail, for example) and it re-looped over and over till you RE-HIT the same key. Then the siren is off. But his code did not prove that. It also didnt prove, when you go from siren, to siren, the old one ended. With the same prob I originally had. It plays 2 or 3 or more sirens at once. Something I also didnt want.....Here is the code......


______________________________________

;;;;;sirenbox by David;;; 
;;;;;;;;;;;;;;;;;;;;;;;;; 
;;;Edited by Yo! Wazzup?;;; 
;;;;;;;;;;;;;;;;;;;;;;;;; 
AppTitle "Sirens" 
Graphics 800,600,24,2 
SetBuffer BackBuffer() 
SeedRnd MilliSecs() 
ClsColor 255,255,255 
Cls 
;Load the image. 
sirenimage = LoadImage("sirenbox.bmp") 
DrawImage sirenimage,20,100 

;load the sounds. 
yelpsound = LoadSound("audio/yelp1.wav") 
airhornsound = LoadSound("audio/air1.wav") 
wailsound = LoadSound("audio/wail1.wav") 
phasersound = LoadSound("audio/ph1.wav") 
hilosound = LoadSound("audio/hilo1.wav") 
manualsound = LoadSound("audio/manual.mp3") 


;Loop 

Repeat 

If KeyHit(2) 
PlaySound yelpsound 
CheckAndStopSounds(yelpsound) 
EndIf 

If KeyHit(3) 
PlaySound airhornsound 
CheckAndStopSounds(airhornsound) 
EndIf 
If KeyHit(4) 
PlaySound wailsound 
CheckAndStopSounds(wailsound) 
EndIf 

If KeyHit(5) 
PlaySound phasersound 
CheckAndStopSounds(phasersound) 
EndIf 

If KeyHit(6) 
PlaySound hilosound 
CheckAndStopSounds(hilosound) 
EndIf 

If KeyHit(7) 
PlaySound manualsound 
CheckAndStopSounds(manualsound) 
EndIf 


;ending 
Until KeyHit(1) 
Flip 

End 


Function CheckAndStopSounds(sound) 
If Not sound = yelpsound Then 
If ChannelPlaying(yelpsound) StopChannel(yelpsound) 
EndIf 
If Not sound = airhornsound Then 
If ChannelPlaying(airhornsound) StopChannel(airhornsound) 
EndIf 
If Not sound = wailsound Then 
If ChannelPlaying(wailsound) StopChannel(wailsound) 
EndIf 
If Not sound = phasersound Then 
If ChannelPlaying(phasersound) StopChannel(phasersound) 
EndIf 
If Not sound = hilosound Then 
If ChannelPlaying(hilosound) StopChannel(hilosound) 
EndIf 
If Not sound = manualsound Then 
If ChannelPlaying(manualsound) StopChannel(manualsound) 
EndIf 

End Function




---------------------------

What went wrong?

You're not actually creating any channels to play your sounds, nor are you looping them.

This should work, although I haven't tested it I'm afraid as at work.

;;;;;sirenbox by David;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
;;;Edited by Yo! Wazzup?;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
AppTitle "Sirens"
Graphics 800,600,24,2
SetBuffer BackBuffer()
SeedRnd MilliSecs()
ClsColor 255,255,255
Cls
;Load the image.
sirenimage = LoadImage("sirenbox.bmp")
DrawImage sirenimage,20,100

;load the sounds.
Global CHANNELyelp = CHANNELcreate( LoadSound("audio/yelp1.wav") )
Global CHANNELairhorn = CHANNELcreate( LoadSound("audio/air1.wav") )
Global CHANNELwail = CHANNELcreate( LoadSound("audio/wail1.wav") )
Global CHANNELphaser = CHANNELcreate( LoadSound("audio/ph1.wav") )
Global CHANNELhilo = CHANNELcreate( LoadSound("audio/hilo1.wav") )
Global CHANNELmanual= CHANNELcreate( LoadSound("audio/manual.mp3") )

Repeat

	If KeyHit(2) CHANNELtoggle( CHANNELyelp )
	If KeyHit(3) CHANNELtoggle( CHANNELairhorn )
	If KeyHit(4) CHANNELtoggle( CHANNELwail )
	If KeyHit(5) CHANNELtoggle( CHANNELphaser )
	If KeyHit(6) CHANNELtoggle( CHANNELhilo )
	If KeyHit(7) CHANNELtoggle( CHANNELmanual )

Until KeyHit(1)

Flip
End

;=========================================================
;=========================================================

Function CHANNELcreate( Sound )

	;loops sound , creates channel, pauses channel
	LoopSound Sound
	Channel = PlaySound( Sound )
	PauseChannel Channel
	Return Channel
	
End Function

;=========================================================
;=========================================================

Function CHANNELtoggle( Channel )

	;pauses / resumes channel
	If Not ChannelPlaying( Channel )
		ResumeChannel Channel
	Else
		PauseChannel Channel
	EndIf
	
End Function

;=========================================================
;=========================================================


btw the manual.mp3 wasnt in the zip

Stevie G: Thank you, I copied the code. Even as happy I am for you helping (will mention in a minute) the code doesnt work. Really, thank you. Even though it doesnt work, I have another peice of code to go over. Than alone is thanks enough.

Ginger Tea: Ya, I realized that afte the upload. For some strange odd reason, mp3's dont upload to that site for some reason. I originally had all of em' mp3, but had to edit, and thought it would be better to also make em .wav's. Manual wasnt edited, as in it wasnt a true manual like explained earlier.

To everyone: Take a good look at these guys. They have given help to a beginer, and to a lame 1st project. Not to say that we dont do it here, but I would like to show gratitude towards them. There have been many times, on forums allover, that 'new' guys, get the blunt of things. Part of it I guess. But it is a lesson to all. Just because you have coded so long, and think you know it all, a small hand does go along way. And some day, I'll hopefully be up there with you. When that happens, Im going to show the 'new' guy, a little help. Again, A GREAT BIG THANKS to you guys for giving a little time.

I also would like to thank another member from Syntaxbomb (hes prob here too LOL) His name there is Andy A. Not only did he show me something, but redid the siren as an App. GREAT JOB. You guys can catch his work here:

http://myfreefilehosting.com/f/f6c1289a82_0.72MB

By the way, hurry in checking out his work, it looks as if its there for a certain amount of time. Awwsome job again. I cant say enough of members like you guys. You guys are real and true coders. :)