Shoutbox

scripting help need please - 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: scripting help need please (/showthread.php?tid=72385)

scripting help need please by Gareth_2007 on 03-07-2007 at 12:31 AM

i have some code that makes merlin talk but where you see merlin.Speak("Hello" + Messenger.MyName); it is only one hello but what i want is every time i log in it is a different hello on random from a hardcoded list! but i dont no how to code it! and where you see merlin.Speak("I'm Merlin, Nice To Meet You!" + Messenger.MyStatus); i want him to say the users satus but he says the status number! any ideas? cheers gareth

function OnEvent_Initialize(MessengerStart){
if(MessengerStart==false){
    startcharacter();
    merlin.Show();
    merlin.MoveTo(25,30);
    merlin.Play("Announce");
    merlin.Speak("Hello" + Messenger.MyName);
    merlin.Play("Greet");
    merlin.Play("RestPose");
    merlin.Speak("I'm Merlin, Nice To Meet You!" + Messenger.MyStatus);

    merlin.Speak("Bye");
    merlin.Play("Wave");
    merlin.Hide();
}else{
        function OnEvent_SigninReady(Email){
            startcharacter();
        }
}
}


RE: scripting help need please by Dennis Mike on 03-07-2007 at 02:56 AM

switch(Messenger.MyStatus){
case 1:
status = "online"
case 2:
status = "etc"
}

merlin.Speak("I'm Merlin, Nice To Meet You!" + status);


RE: scripting help need please by Felu on 03-07-2007 at 03:14 AM

Or you can make an array with Status names and Match it with Status code :).

code:
var Status = new Array("Unknown", "Offline", "Appear Offline", "Online", "Busy", "Be Right Back", "Idle", "Away", "In a Call", "Out to Lunch");
Status[Messenger.MyStatus];

RE: scripting help need please by CookieRevised on 03-07-2007 at 11:44 AM

Gareth_2007,

Note that your general code is completely wrong though. It will not function properly and will returns errors in some cases:

code:
function OnEvent_Initialize(MessengerStart){
    if(MessengerStart==false){
        startcharacter();
        merlin.Show();
        merlin.MoveTo(25,30);
        merlin.Play("Announce");
        merlin.Speak("Hello" + Messenger.MyName);
        merlin.Play("Greet");
        merlin.Play("RestPose");
        merlin.Speak("I'm Merlin, Nice To Meet You!" + Messenger.MyStatus);

        merlin.Speak("Bye");
        merlin.Play("Wave");
        merlin.Hide();
    }else{
        function OnEvent_SigninReady(Email){
            startcharacter();
        }
    }
}

Fixed for what you probably want to do:
code:
function OnEvent_Initialize(MessengerStart){
    if(Messenger.MyStatus > 1){
        OnEvent_SigninReady(Messenger.MyEmail);
    }
}

function OnEvent_SigninReady(Email){
        startcharacter();
        merlin.Show();
        merlin.MoveTo(25,30);
        merlin.Play("Announce");
        merlin.Speak("Hello " + Messenger.MyName);
        merlin.Play("Greet");
        merlin.Play("RestPose");
        merlin.Speak("I'm Merlin, Nice To Meet You! Your status is " + Array("Unknown", "Offline", "Appear Offline", "Online", "Busy", "Be Right Back", "Idle", "Away", "In a Call", "Out to Lunch")[Messenger.MyStatus]);

        merlin.Speak("Bye");
        merlin.Play("Wave");
        merlin.Hide();
}

;)




-------------------------------------------------------------------
quote:
Originally posted by Dennis Mike
switch(Messenger.MyStatus){
case 1:
status = "online"
1 = "Offline", not "Online"


RE: scripting help need please by Gareth_2007 on 03-07-2007 at 01:55 PM

cheer for the help guys! how can i get merlin to choose form a list of different hellos so when you sign in it will be a different hello on random? cheers


RE: scripting help need please by CookieRevised on 03-07-2007 at 02:52 PM

The principle is the same as what you do with the status text.

You create an array of different texts. Then you need to get a random number which would be the number of the element to take from that array.

Random numbers can be generated like this:

code:
var myRandomNumber = Math.floor((upperbound - lowerbound + 1) * Math.random() + lowerbound);
where upperbound is the biggest number and lowerbound the lowest number in the range you which to choose from.

Thus if you whish to choose a random number from 5 to 10, you do:
code:
var myRandomNumber = Math.floor((10 - 5 + 1) * Math.random() + 5);
which equals:
code:
var myRandomNumber = Math.floor(6 * Math.random() + 5);

For the array of random texts, it is important to know that arrays start with index 0 (thus this would be our lowerbound). The length of the array determines our upperbound:
code:
var myTextArray = new Array("Hello", "Bonjour", "Yo", "Hi");

var lowerbound = 0;
var upperbound = myTextArray.length-1;

var myRandomNumber = Math.floor((upperbound - lowerbound + 1) * Math.random() + lowerbound);

var myRandomText = myTextArray[myRandomNumber];
optimized, this would be:
code:
var myTextArray = new Array("Hello", "Bonjour", "Yo", "Hi");
var myRandomText = myTextArray[Math.floor(myTextArray.length * Math.random())];