Shoutbox

How To Call Upon Random Files - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: How To Call Upon Random Files (/showthread.php?tid=63773)

How To Call Upon Random Files by Vexor on 07-22-2006 at 09:45 AM

I am looking for a way to call upon a random sound file from a directory? mainly so that when I sign in, I want it to play a different song? it can either open the song or play the song.

Also is there a script out there that has something that has a random message for the day toast displayer, cos I think I would use one of these.


RE: How To Call Upon Random Files by John Anderton on 07-22-2006 at 10:56 AM

Use the random function (in jscript) to get a number and use the if condition to play a different file.

This of course works only if you know the file names. Or you could do search the directory and store all its files in an array and then generate a random number (using jscript) and use it as the subscript of the array giving you a random file to everytime :)


RE: How To Call Upon Random Files by Vexor on 07-22-2006 at 06:10 PM

ok, so as in if i had the files named 1.mp3, 2.mp3, 3.mp3 and so on, how would i write this?


RE: How To Call Upon Random Files by -dt- on 07-22-2006 at 06:21 PM

quote:
Originally posted by Vexor
ok, so as in if i had the files named 1.mp3, 2.mp3, 3.mp3 and so on, how would i write this?
Step 1: type http://google.com into your web browser
Step 2: type "jscript how to make random numbers"
Step 3: hit enter
Step 4: then open results until you find your answer
RE: How To Call Upon Random Files by Hengy on 07-22-2006 at 08:11 PM

You could always make a windows media player playlist and always have shuffle on...


RE: How To Call Upon Random Files by Vexor on 07-23-2006 at 12:02 AM

Ok that didnt help, I was looking for a way to do it so that when ever i signed into WLM it would play a random sound, but it doesnt matter.


RE: How To Call Upon Random Files by cloudhunter on 07-23-2006 at 12:04 AM

Ah, you should have said "sound" then not "music" ;) But it's possible I think. You just need to find a way of playing the sound :) Follow -dt-'s advice and google it, it should be pretty well known :)

Cloudy


RE: How To Call Upon Random Files by Vexor on 07-24-2006 at 08:42 AM

quote:
Originally posted by cloudhunter
Ah, you should have said "sound" then not "music" ;) But it's possible I think. You just need to find a way of playing the sound :) Follow -dt-'s advice and google it, it should be pretty well known :)

Cloudy

I did put sound down every time, i didnt mention music. I been looking, but I cant seem to find anything that will help me.
RE: How To Call Upon Random Files by Veggie on 07-24-2006 at 10:07 AM

http://www.pageresource.com/jscript/jrandom.htm
first result ffs


RE: How To Call Upon Random Files by Vexor on 07-24-2006 at 10:35 AM

Ok then, I tried this from a while ago when i went to that site, and this is what i came up with.

and no surprises, but I cannot get it to work. it is simple, but well I hope it will get me started in loading random things from scripts.

any ideas how i can make this work?

I tried everything "I" can think of.

code:
function getaSound()
{
   var whichsound=get_random();

    var quote=new Array(2)
     quote[0]="Chimes.WAV";
     quote[1]="Ding.WAV";
  }
 
function OnEvent_ChatWndCreated(ChatWnd)
{
var ChatWndContacts = ChatWnd.Contacts;
if(ChatWndContacts.Count == 1)
{
var e = new Enumerator(ChatWndContacts);
var Contact = e.item();
{
MsgPlus.DisplayToastContact(Messenger.MyName , "Has Just Opened A Window With" , Contact.Name , getaSound );

}
}
}




RE: RE: How To Call Upon Random Files by foaly on 07-24-2006 at 10:39 AM

quote:
Originally posted by Vexor
Ok then, I tried this from a while ago when i went to that site, and this is what i came up with.

and no surprises, but I cannot get it to work. it is simple, but well I hope it will get me started in loading random things from scripts.

any ideas how i can make this work?

I tried everything "I" can think of.

code:
function getaSound()
{
   var whichsound=get_random();

    var quote=new Array(2)
     quote[0]="Chimes.WAV";
     quote[1]="Ding.WAV";
  }
 
function OnEvent_ChatWndCreated(ChatWnd)
{
var ChatWndContacts = ChatWnd.Contacts;
if(ChatWndContacts.Count == 1)
{
var e = new Enumerator(ChatWndContacts);
var Contact = e.item();
{
MsgPlus.DisplayToastContact(Messenger.MyName , "Has Just Opened A Window With" , Contact.Name , getaSound );

}
}
}





well getaSound doesn't return a audio file... try something like:

code:
function getaSound()
{
   var whichsound=get_random();

    var quote=new Array(2)
     quote[0]="Chimes.WAV";
     quote[1]="Ding.WAV";
     return quote[whichsound];
}

 
RE: How To Call Upon Random Files by Vexor on 07-24-2006 at 11:03 AM

How do i get my other function to open that command? as in from the

code:
MsgPlus.DisplayToastContact(Messenger.MyName , "Has Just Opened A Window With" , Contact.Name , sound[whichsound]);
I am trying this and it is not working.? is it wrong?
--EDIT--

ok I have been playing around a bit more and after pulling some old scripts apart, i managed to find a few with different out lays on how to trigger from a different function.

can you let me know what you thinka nd what ineed to change to get this to work.

code:

function getaSound(){
var whichsound=get_random();
var sound=new Array(2)
  sound[0]="CHIMES.WAV";
  sound[1]="LeaveMeAlone.mp3";
return sound[whichsound];
}

function OnEvent_ChatWndCreated(ChatWnd){
var ChatWndContacts = ChatWnd.Contacts;
if(ChatWndContacts.Count == 1)
{
  var e = new Enumerator(ChatWndContacts);
  var Contact = e.item();
  {
   MsgPlus.DisplayToastContact(Messenger.MyName , "Has Just Opened A Window With" , Contact.Name , "");
   getaSound();
  }
}
}



Really do need help.

RE: How To Call Upon Random Files by Pai on 07-24-2006 at 11:25 AM

what's get_random() anyway ? to generate a random number you have to use Math.Random() ... unless you created a function to do this and named it get_random(), but as you didn't post them I have to ask :p

then, you don't use sound[whichsound] again in the toast, you first call the function and assign the result to a variable, which already contains the filename. Something like this:

code:
var fileName = getaSound();
MsgPlus.DisplayToastContact(Messenger.MyName , "Has Just Opened A Window With" , Contact.Name , fileName);

Remember, the files must be  in your script's directory. If you have them in a subdirectory like "sounds", you have to use:
code:
MsgPlus.DisplayToastContact(Messenger.MyName , "Has Just Opened A Window With" , Contact.Name , "sounds\"+fileName);

RE: How To Call Upon Random Files by Vexor on 07-24-2006 at 11:38 AM

code:
function get_random(){
var ranNum=Math.floor(Math.random()*2);
return ranNum;
}

function getaSound(){
var whichSound=get_random();

var sound=new Array(2)
sound[0]="CHIMES.WAV";
sound[1]="LeaveMeAlone.mp3";
alert(sound[whichSound]);
}

function OnEvent_ChatWndCreated(ChatWnd){
var ChatWndContacts = ChatWnd.Contacts;
if(ChatWndContacts.Count == 1)
{
  var e = new Enumerator(ChatWndContacts);
  var Contact = e.item();
  {
   var fileName = getaSound();
   MsgPlus.DisplayToastContact(Messenger.MyName , "Has Just Opened A Window With" , Contact.Name , fileName);
  }
}
}





This still doe snot work and Ihave all that you have said to put in there. what am i missing here?

--EDIT--

code:
function getaSound(){
var whichSound=get_random();

var sound=new Array(2)
sound[0]="CHIMES.WAV";
sound[1]="LeaveMeAlone.mp3";
alert(sound[whichSound]);
}
was ment to be
code:
function getaSound(){
var whichSound=get_random();

var sound=new Array(2)
sound[0]="CHIMES.WAV";
sound[1]="LeaveMeAlone.mp3";
return sound[whichSound];
}

Sorry for your trouble. I got it working now.

Thank you all so much.