Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random music
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
upthescale




PostPosted: Fri May 12, 2006 5:39 pm   Post subject: 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)
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Fri May 12, 2006 5:58 pm   Post subject: (No subject)

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:
pseudocode:
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:
pseudocode:
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




PostPosted: Fri May 12, 2006 7:42 pm   Post subject: (No subject)

Another easy way is to use a simple number file system. Say file number one is called death.wav so...
code:
change;
death1.wav

to;
1.wav
Then 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;
code:
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;
code:
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;
code:
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;
code:
var a :int
var b :string
a:=100
b:=intstr(a)
put b

Simple right? So let's make the code;

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]




PostPosted: Fri May 12, 2006 11:00 pm   Post subject: (No subject)

Yep, the number to string method will work. It's what I meant with:
[Gandalf] wrote:
pseudocode:
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




PostPosted: Sun May 14, 2006 8:45 am   Post subject: (No subject)

[Gandalf] wrote:
Yep, the number to string method will work. It's what I meant with:
[Gandalf] wrote:
pseudocode:
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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: