Shoutbox

[Request] Disable/Enable. - 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: [Request] Disable/Enable. (/showthread.php?tid=94343)

[Request] Disable/Enable. by Seed on 04-09-2010 at 07:54 PM

Hi people,

I'm french so, i'm really sorry if you don't understand me immediatly. I'll try to do the best i can. :/

So, i need to get a part of script to active/desactive my script with a variable for example. I mean, a menu with the name of my script, and one option : "Disable" and "Enable", When my script is enable, i want a var with 1, and Disable 0. ^^

But i really don't know how to do that, i was trying with some scripts (Like Answering Machine Plus!), but i can't do same. Can you please help me ? ^^

Thanx,
Best regards.

EDIT : And on my JS, i'll need to do a if(Enable == 1), but i don't know how to get the var.. please help. ^.^

EDIT ² : I can make it with "goto", but i don't know how to place "goto". :/


RE: [Request] Disable/Enable. by whiz on 04-09-2010 at 08:15 PM

js code:
var Enabled = 1;

function OnGetScriptMenu()
{
    var Menu = "<ScriptMenu>";
    Menu += "    <MenuEntry Id=\"ToggleEnable\">" + (Enabled ? "En" : "Dis") + "able...</MenuEntry>";
    return Menu + "</ScriptMenu>";
}

function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd)
{
    switch (MenuItemId)
    {
        case "ToggleEnable":
            Enabled = !Enabled; // toggle the value
            break;
        // add additional menu items here...
    }
}

That'll make a menu, which, when enabled, will display "Disable...", and when disabled, will display "Enable...".

Also...  using "goto" is for batch files, not JScript.  :)
RE: [Request] Disable/Enable. by matty on 04-09-2010 at 08:15 PM

Add a variable called Enable at the top of any of the JS files?


RE: [Request] Disable/Enable. by Seed on 04-09-2010 at 08:51 PM

Nice Whiz it's what i want but i got some problem.

Look my code :

code:
var Enabled = 0;

function OnGetScriptMenu()
{
    var Menu = "<ScriptMenu>";
    if(Enabled==0) { Menu += "   <MenuEntry Id=\"ToggleEnable\">Enable</MenuEntry>"; }
    if(Enabled==1) { Menu += "   <MenuEntry Id=\"ToggleEnable\">Disable</MenuEntry>"; }
    return Menu + "</ScriptMenu>";
}

function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd)
{
    switch (MenuItemId)
    {
        case "ToggleEnable":
            if(Enabled == 1) { Enabled = 0; }
            if(Enabled == 0) { Enabled = 1; }
            break;
        // add additional menu items here...
    }
}

And after :

code:
if(Enabled==1)
{
[...]My Code[...]
}
else
{
function OnEvent_ChatWndSendMessage(ChatWnd,Message)
{
if(Message=="!is_activated"){

return "Result is : " + Enabled;
}
}
}

But my code does not work.. (After the if), when i do !is_activated, answer is 1 (Enabled). But after, don't work.

A part of my code :

code:
if(Enabled==1)
{
function SendMessage(sMessage)
{
return sMessage;
}

function OnEvent_ChatWndSendMessage(ChatWnd,Message){

if(Message=="Email"){
return 'blabla';
}

When i type "Email", return is.. "Email". 8-|

Do you know why ?

Thanx,
Best regards !

EDIT : The menu works, it's just my code, i think it's the "if". :/
RE: [Request] Disable/Enable. by matty on 04-09-2010 at 09:45 PM

I suggest posting all of your code not just snippets. And use the following tags:

[code=js][/code]


RE: [Request] Disable/Enable. by Spunky on 04-09-2010 at 11:03 PM

js code:
            if(Enabled == 1) { Enabled = 0; }
            if(Enabled == 0) { Enabled = 1; }

Could just be:
js code:
Enabled = !Enabled;

Also, the ChatWndSendMessage event appears to be in an if statement... No experience with this (I'm guessing though it's not right), but I would say that's why it only works properly in one condition.
RE: RE: [Request] Disable/Enable. by Volv on 04-09-2010 at 11:18 PM

js code:
            if(Enabled == 1) { Enabled = 0; }
            if(Enabled == 0) { Enabled = 1; }
You need to use an Else (or what Spunky said), otherwise it will always be 1.
RE: [Request] Disable/Enable. by Seed on 04-10-2010 at 10:54 AM

Fixed.

And the code works, i just move the 'if' after the 'function' and it's works fine.

Thanx for all ! :)