
-----------------------------------
upthescale
Fri May 12, 2006 5:39 pm

Random music
-----------------------------------
im making a game haqt  iwill post so shortly...i have two sounds when i shoot the guys i want the sound to either do the siren sound, or the guy dying, is there that turing can randomly pick a sound? (siren or dieing)

-----------------------------------
[Gandalf]
Fri May 12, 2006 5:58 pm


-----------------------------------
This shouldn't be a problem for any programmer...  You have got to think more generic when you look at a language, you can't expect every possible code for every possible function will be written for you.  Why don't just use something like:
if a random number between 1 and 2 is two
choose song 2
or if a random number between 1 and 2 is one
choose song 1
or better yet, if you want many more songs:
let i be the amount of songs to choose from
let randomNumber store a random number between 1 and i
choose song named randomNumber

Also what does "haqt" mean?

-----------------------------------
AzureFire
Fri May 12, 2006 7:42 pm


-----------------------------------
Another easy way is to use a simple number file system. Say file number one is called death.wav so... change;
death1.wav

to;
1.wavThen do the same for the rest. When you make the program in Turing you will want to randomize a number, from the first file name, to the last. eg;
Rand.Int(1,2) %randomizes a number between 1 and 2
Then you'll need to use String Concatenation. This is simply joining two strings together. You can do this with the + operator. eg;
var a, b, c, full:string
a:= "Sally "
b:= "is "
c:= "dumb!"
full:= a + b + c
put full

You can also do it this way;
var a, c, full:string
a:= "Sally"
c:= "dumb!"
full:= a + " is " + c
put full

The only problem is that when you call the sound file, you cannot use an integer. You will need to use intstr(). Like this;
var a :int
var b :string
a:=100
b:=intstr(a)
put b
Simple right? So let's make the code;

Music.PlayFile(intstr(Rand.Int(1,2))+".wav")

There, nice one-liner with no variables. I really hope that this is easily understandable. This is one of the simplest ways to do this, if this is hard to figure out, time to do some reading and fiddling. Learn by making mistakes and fixing them, and also help files do as the name suggests.

P.S. I haven't tested any of this. Feel free to do so.

-----------------------------------
[Gandalf]
Fri May 12, 2006 11:00 pm


-----------------------------------
Yep, the number to string method will work.  It's what I meant with: 
"]let i be the amount of songs to choose from
let randomNumber store a random number between 1 and i
choose song named randomNumber

-----------------------------------
AzureFire
Sun May 14, 2006 8:45 am


-----------------------------------
"]Yep, the number to string method will work.  It's what I meant with: 
"]let i be the amount of songs to choose from
let randomNumber store a random number between 1 and i
choose song named randomNumber
Ahhh, I read it wrong, I thought you were talking about making a for loop and playing each one, one after another.
