Shoutbox

How to make a menu and commands? - 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 make a menu and commands? (/showthread.php?tid=89092)

How to make a menu and commands? by Dr Nick on 02-11-2009 at 02:51 AM

Hi, I have developed a script that rotates my PM, and changes it depending on what my status is.

I wish to develop a menu (in the scripts menu) that will allow me to enable/ disable this script (I have made a variable that will allow me to do this, but I have to be able to change this variable with a menu click [this is only if there is no easier way to disable the script]).

I also want to make a command that will call a function to force the PM to rotate if I wish to make it rotate faster than the normal speed.

How would I do this?

Thanks for your help!
Nick


RE: How to make a menu and commands? by matty on 02-11-2009 at 01:46 PM

Menu functions:

js code:
function OnGetScriptMenu(nLocation){
    var oMenu = new ScriptMenu();
       
    with (oMenu) {
        AddSubMenu('My Menu'));
            AddItem('/mycommand1', 'My Command without parameter');
            AddItem('/mycommand1 5', 'My command with parameter');
            AddSeperator();
            AddItem('', 'Disabled item', false);
        CloseSubMenu();
    }
    return oMenu.ExportMenu();
}

function OnEvent_MenuClicked(sMenuId, nLocation, oChatWnd){
    OnEvent_ChatWndSendMessage(oChatWnd, sMenuId);
}

Command functions:
js code:
function OnGetScriptCommands(){
    var oCommand = new Commands();
    with (oCommand) {
        AddCommand('mycommand1', 'My command without parameter');
        AddCommand('mycommand1', 'My command with parameter', 5);
    }
    return oCommand.ExportCommands();   
}

function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMenuId) !== null) {
        var _command = RegExp.$1.toLowerCase();
        var _param = RegExp.$2;
        switch (_command) {
            case 'mycommand':
                if ( _param !== '' ) {
                    /*
                        Do stuff here
                    */
                } else {
                    /*
                        Do stuff here
                    */
                }
                break;
        }
    }
}

RE: How to make a menu and commands? by Spunky on 02-11-2009 at 02:35 PM

quote:
Originally posted by matty
js code:




Shouldn't that be:

js code:
function OnGetScriptCommands(){
    var oCommand = new Commands();
    with (oCommand) {
        AddCommand('mycommand1', 'My command without parameter');
        AddCommand('mycommand1', 'My command with parameter', 5);
    }
    return oCommand.ExportCommands();   
}

:p
RE: How to make a menu and commands? by matty on 02-11-2009 at 03:18 PM

quote:
Originally posted by Spunky
quote:
Originally posted by matty
js code:




Shouldn't that be:

js code:
function OnGetScriptCommands(){
    var oCommand = new Commands();
    with (oCommand) {
        AddCommand('mycommand1', 'My command without parameter');
        AddCommand('mycommand1', 'My command with parameter', 5);
    }
    return oCommand.ExportCommands();   
}

:p
Yes you are correct!
RE: How to make a menu and commands? by Dr Nick on 02-12-2009 at 06:30 AM

Thanks, But I have tried this and when I try to start the script after changing it, I am told that I dont have the permissions to run it, or it is defective. Am I doing something wring here?

Thanks
Nick


Now it works (I removed a ")" in the menu bit) but i get the following error, and the commands / menu dont work:
Error: Object expected (code: -2146823281)
       File: __commands.js. Line: 15.
Function OnGetScriptCommands returned an error. Code: -2147352567
And when I try to send a message
Function called: OnEvent_ChatWndSendMessage
Error: 'sMenuId' is undefined (code: -2146823279)
       File: Status Checker.js. Line: 145.
Function OnEvent_ChatWndSendMessage returned an error. Code: -2147352567

RE: How to make a menu and commands? by djdannyp on 02-12-2009 at 10:50 AM

post your entire code using [code=xml][/code] tags around it so that it get highlighted properly, as matty and Spunky did


RE: How to make a menu and commands? by matty on 02-12-2009 at 01:56 PM

Wow I guess I should look at my coding before posting it...

Ok first things first in __commands.js we need to edit a line

js code:
(typeof sParameter === 'undefined' ? '' : '<Parameters>&lt;'+LoadString('CommandDelay')+'&gt;</Parameters>')+
Change to:
js code:
>>>(typeof sParameter === 'undefined' ? '' : '<Parameters>&lt;'+sParameter+'&gt;</Parameters>')+<<<
Glad I found this because the code is used in Screenshot Sender as well! Oopsies!

And these functions needs to be changed:
js code:
function OnGetScriptCommands(){
    var oCommand = new Commands();
    with (oCommand) {
        AddCommand('mycommand1', 'My command without parameter');
>>>        AddCommand('mycommand1', 'My command with parameter', 'Enter a parameter');<<<
    }
    return oCommand.ExportCommands();   
}


function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
>>>    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {<<<
        var _command = RegExp.$1.toLowerCase();
        var _param = RegExp.$2;
        switch (_command) {
            case 'mycommand':
                if ( _param !== '' ) {
                    /*
                        Do stuff here
                    */
                } else {
                    /*
                        Do stuff here
                    */
                }
                break;
        }
    }
}

RE: How to make a menu and commands? by Dr Nick on 02-13-2009 at 06:55 AM

Better, but i renamed the commands, and edited the menu etc, but nothing works.

The commands show up in the command list, but when i enter them, it says the command was not recognised...

Also, when the button in the menu is clicked, the function is not called...

Here is my code...
The code for the menu and command is down the very bottom

xml code:
var originalPSM;
var idleSeconds;
var isIdle;
var isBusy;
var PSMnumber;
var seconds = 60;

function OnEvent_Initialize(MessengerStart)
{
    idleSeconds = 0;
    isIdle = false;
    isBusy = false;
    MsgPlus.AddTimer('rotate', seconds * 1000);
}

function OnEvent_Uninitialize(MessengerExit)
{
}

function updateMessage() {
        if(PSMnumber==1) {
            originalPSM = "Growing old is mandatory, growing up is optional";
            PSMnumber=2;
        } else {
            originalPSM = "There are only two ways to live your life. One is as though nothing is a miracle. The other is as if everything is.";
            PSMnumber=1;
        }
        Messenger.MyPersonalMessage = originalPSM;
}

function OnEvent_MyStatusChange(NewStatus)
{
    if( NewStatus == 7 || NewStatus == 6 )
    {
        Messenger.MyPersonalMessage = "Text/ ring me and I'll be back ASAP! 0hrs:0mins:0secs";
        MsgPlus.AddTimer( "incIdle", 1000 );
        MsgPlus.AddTimer( "updateDisplay", 6000 );
        isIdle = true;
        isBusy = false;
    } else if(NewStatus == 4) {
        Messenger.MyPersonalMessage = "Text me! I'm in a full screen app and mssngr alerts are off! :)";
        isBusy = true;
        isIdle = false;
        idleSeconds = 0;
    }
    else
    {
        isIdle = false;
        isBusy = false;
        idleSeconds = 0;
        updateMessage();
        MsgPlus.AddTimer('rotate', seconds * 1000);
    }
}

function OnEvent_Timer(sTimerId)
{
    if( isIdle == false && isBusy == false)
    {
        updateMessage();
        MsgPlus.AddTimer('rotate', seconds * 1000);
        return 0;
    }
    else if( sTimerId == "incIdle" )
    {
        if(isIdle==true) {
            idleSeconds ++;
            MsgPlus.AddTimer( "incIdle", 1000 );
        }
    }
    else if( sTimerId == "updateDisplay" )
    {
        if(isIdle==true) {
            var cIdleSeconds = idleSeconds;
            var idleHours = 0;
            var idleMinutes = 0;
           
            while( cIdleSeconds > 59 )
            {
                cIdleSeconds -= 60;
                idleMinutes ++;
            }
           
            while( idleMinutes > 59 )
            {
                idleMinutes -= 60;
                idleHours ++;
            }
   
            Messenger.MyPersonalMessage = "Text/ ring me and I'll be back ASAP! "+idleHours+"hrs:"+idleMinutes+"mins:"+cIdleSeconds+"secs";
            MsgPlus.AddTimer( "updateDisplay", 6000 );
        }
    }
}

function OnGetScriptCommands(){
    var oCommand = new Commands();
    with (oCommand) {
        AddCommand('PMrotate', 'Rotate your Personal Message');    }
    return oCommand.ExportCommands(); 
}

function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {        var _command = RegExp.$1.toLowerCase();
        var _param = RegExp.$2;
        switch (_command) {
            case 'PMrotate':
                if ( _param !== '' ) {
                    updateDisplay();
                } else {
                    updateDisplay();
                }
                break;
        }
    }
}

function OnGetScriptMenu(nLocation){
    var oMenu = new ScriptMenu();
       
    with (oMenu) {
        AddSubMenu('My Menu');
            AddItem('/PMrotate', 'Roate your Personal Message');
        CloseSubMenu();
        AddItem('/PMrotate', 'Roate your Personal Message');
    }
    return oMenu.ExportMenu();
}

function OnEvent_MenuClicked(sMenuId, nLocation, oChatWnd){
    OnEvent_ChatWndSendMessage(oChatWnd, sMenuId);
}
I also have the two files from Matty

RE: How to make a menu and commands? by Dr Nick on 02-13-2009 at 06:58 AM

I also plan on adding a command such as:
/addPM "This is my PM"
So the Pm's will be stored in an array or something, and you can add to it with a command.

Any ideas on how I could do this?

Thanks for all the help!
Nick


RE: How to make a menu and commands? by Th3rmal on 02-13-2009 at 07:06 AM

quote:
Originally posted by Dr Nick
I also plan on adding a command such as:
/addPM "This is my PM"
So the Pm's will be stored in an array or something, and you can add to it with a command.

Any ideas on how I could do this?

Thanks for all the help!
Nick
I dont script, but IIRC the solution to this kind of thing is usually to store it in a text file, then get the script to read it off the text file. Although i could be horribly wrong :P
RE: How to make a menu and commands? by matty on 02-13-2009 at 07:08 AM

Well based on your code you don't have an updateDisplay function you have an updateMessage function. It would help if you posted the contents of the script debugger window when you try to use your script.


RE: How to make a menu and commands? by Dr Nick on 02-13-2009 at 08:08 AM

Thanks. I replaced the display with message, but still I have the same problem...

code:
Script is starting
Script is now loaded and ready
Function called: OnEvent_Initialize
Function called: OnGetScriptMenu
Function called: OnEvent_MenuClicked
Function called: OnGetScriptCommands
Function called: OnEvent_ChatWndSendMessage


As far as I know, I have no function OnEvent_MenuClicked...

I am still getting that annoying message pop up when I try to send the command

Thanks again
RE: How to make a menu and commands? by matty on 02-13-2009 at 01:45 PM

Not at home at the moment therefore I cannot test this to verify it works however with regards to this:

quote:
Originally posted by Dr Nick
As far as I know, I have no function OnEvent_MenuClicked...

I am still getting that annoying message pop up when I try to send the command
You do have a function called OnEvent_MenuClicked and it is being called you just have an error in the OnEvent_ChatWndSendMessage function.

js code:
var originalPSM;
var idleSeconds;
var isIdle;
var isBusy;
var PSMnumber;
var seconds = 60;

function OnEvent_Initialize(MessengerStart){
    idleSeconds = 0;
    isIdle = false;
    isBusy = false;
    MsgPlus.AddTimer('rotate', seconds * 1000);
}

function updateMessage() {
        if(PSMnumber==1) {
            originalPSM = "Growing old is mandatory, growing up is optional";
            PSMnumber=2;
        } else {
            originalPSM = "There are only two ways to live your life. One is as though nothing is a miracle. The other is as if everything is.";
            PSMnumber=1;
        }
        Messenger.MyPersonalMessage = originalPSM;
}

function OnEvent_MyStatusChange(NewStatus){
    if( NewStatus == 7 || NewStatus == 6 )
    {
        Messenger.MyPersonalMessage = "Text/ ring me and I'll be back ASAP! 0hrs:0mins:0secs";
        MsgPlus.AddTimer( "incIdle", 1000 );
        MsgPlus.AddTimer( "updateDisplay", 6000 );
        isIdle = true;
        isBusy = false;
    } else if(NewStatus == 4) {
        Messenger.MyPersonalMessage = "Text me! I'm in a full screen app and mssngr alerts are off! :)";
        isBusy = true;
        isIdle = false;
        idleSeconds = 0;
    }
    else
    {
        isIdle = false;
        isBusy = false;
        idleSeconds = 0;
        updateMessage();
        MsgPlus.AddTimer('rotate', seconds * 1000);
    }
}

function OnEvent_Timer(sTimerId){
    if( isIdle == false && isBusy == false)
    {
        updateMessage();
        MsgPlus.AddTimer('rotate', seconds * 1000);
        return 0;
    }
    else if( sTimerId == "incIdle" )
    {
        if(isIdle==true) {
            idleSeconds ++;
            MsgPlus.AddTimer( "incIdle", 1000 );
        }
    }
    else if( sTimerId == "updateDisplay" )
    {
        if(isIdle==true) {
            var cIdleSeconds = idleSeconds;
            var idleHours = 0;
            var idleMinutes = 0;
           
            while( cIdleSeconds > 59 )
            {
                cIdleSeconds -= 60;
                idleMinutes ++;
            }
           
            while( idleMinutes > 59 )
            {
                idleMinutes -= 60;
                idleHours ++;
            }
   
            Messenger.MyPersonalMessage = "Text/ ring me and I'll be back ASAP! "+idleHours+"hrs:"+idleMinutes+"mins:"+cIdleSeconds+"secs";
            MsgPlus.AddTimer( "updateDisplay", 6000 );
        }
    }
}

function OnGetScriptCommands(){
    var oCommand = new Commands();
    with (oCommand) {
        AddCommand('pmrotate', 'Rotate your Personal Message');    }
    return oCommand.ExportCommands(); 
}

function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {       
        var _command = RegExp.$1.toLowerCase();
        var _param = RegExp.$2;
        switch (_command) {
>>>            case 'pmrotate':<<<
                    updateMessage();
                    break;
        }
    }
}

function OnGetScriptMenu(nLocation){
    var oMenu = new ScriptMenu();
       
>>>    oMenu.AddItem('/pmrotate', 'Roate your Personal Message');<<<
   
    return oMenu.ExportMenu();
}

function OnEvent_MenuClicked(sMenuId, nLocation, oChatWnd){
    OnEvent_ChatWndSendMessage(oChatWnd, sMenuId);
}

The highlighted stuff is what I changed.
RE: How to make a menu and commands? by Dr Nick on 02-13-2009 at 11:41 PM

OK, thanks a heap, Matty.

The menu works perfectly now, but the command only kinda works.

When i enter the command, my PM rotates manually through the PM's in the script, as it should, but then an error message pops up, same as before saying that it wasn't recognised as a command, and if it wasnt mean to be, enter another / at the beginning...

Any ideas on this?

Thanks so much for your help so far,
Nick.


RE: How to make a menu and commands? by matty on 02-14-2009 at 04:23 AM

Wow I really am feeling embarrassed right now... I shouldn't be making these mistakes...

js code:
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {       
        var _command = RegExp.$1.toLowerCase();
        var _param = RegExp.$2;
        switch (_command) {
            case 'pmrotate':
                    updateMessage();
>>>                    return '';<<<
                    break;
        }
    }
}

The reason you need to return false is because if you do not Messenger Plus! tries to parse the command and since it isn't recognized it fails.
RE: How to make a menu and commands? by Dr Nick on 02-14-2009 at 08:02 AM

Wow, works perfectly!

Thanks a bunch, Matty! :D

I still have a lot of work to do, but hopefully I'll be able to do it myself from here on! :)

Thanks a heap,
Nick