What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » script command error - "Command Requiers Parameter"

script command error - "Command Requiers Parameter"
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: script command error - "Command Requiers Parameter"
billboy1001 (and others), now that you know what the cause was for that error, there are some other major pitfalls in your script and things you should now about:

first, as a sidenote, note that the above fixed scripts all made the nick variable local. Since you use a timer to restore the nickname, that variable should be global (as you did it in your original script) and not local as in the fixed snippets.

1) May I suggest not to use mCommand = Message.split(' '); and that code to get the parameters. It is bound to produce not the result you want when you (accidently or not) have more than one space. Hence the nickname wont always be in mCommand[1].

And if you forget to enter some text to be used for the me command on the parameter line, the script will produce that same "command needs parameter" too.

2) The use of timers:
Be extremely carefull with that. I also use the timer event (obviously), but do you make sure in that event that the logged in user is still the same user who started the timer? If not, and you sign out before the timer has triggered, you actually will change the nickname of the newly logged in user.

Also, by the use of the timer as you use it, there is no garantee that the timer will be triggered after the /me command has done its job. The timer might as well be triggered before the /me command, and thus the script will not restore your nickname properly.

3) When you return a message in the OnEvent_ChatWndSendMessage() with the /me command, it will _not_ be interpreted as a command, but as a pure text. This is probably a bug in Messenger Plus! Live. <= fixed in latest Plus! version.

4) Nickchanges and commands take their time (though it usually is performed within some milliseconds; it still takes some milliseconds time). This means that you can not expect the nickchange to have happened before you send the /me command and that you can not expect the /me command to have happened before restoring the nickname.


As you see, what you want to do seems easy enough, but it is actually far from strait forward...

But, first things first. Suppose problem 2, 3 and 4 don't exist, then you still should be using something like this instead:
code:
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
        if (new RegExp(/^\/act\s+(\S+)\s+(.+)$/i).exec(sMessage) != null) {
                var nick = Messenger.MyName;
                Messenger.MyName = RegExp.$1;
                MsgPlus.AddTimer("restoreNick", 100);
                return "/me " + RegExp.$2;
        }
}
Notice how much shorter and strait forward the code actually is...
And may I also suggest:
code:
function OnGetScriptCommands() {
        return "<ScriptCommands>"
                +    "<Command>"
                +        "<Name>act</Name>"
                +        "<Description>Sends an action message that starts with a custom name</Description>"
                +        "<Parameters>&lt;name&gt; &lt;message&gt;</Parameters>"
                +    "</Command>"
                + "</ScriptCommands>";
}

Now, as for the rest of the problems. Those can only be dealed with if you make a script which will trigger an action and wait for that action to be ended before doing another action.

So you need to wait until the name has changed before you actually can perform the /me command. Then you have to wait till that is finished and only then you can change the nick back.

You would think you could do all this by using a combination of the events: OnEvent_MyNameChange, OnEvent_ChatWndSendMessage or OnEvent_ChatWndReceiveMessage.

However, this will not work!!!

First of all, OnEvent_ChatWndReceiveMessage isn't always triggered when you send a new command message back to the chatwindow in response to an OnEvent_ChatWndSendMessage event.

Second, and most importantly, all those events are triggered _before_ the message is handled or nick is changed. So if you do something in those event functions it will not be performed after those events (as we need it to be), but before the events!

To fix all this you _must_ revert back to a dirty workaround using a timer. There is no other way around it (using only pure scripting):

The fixed code:
code:
var oldNick = "";
var actNick = "";
var actMessage = "";
var actWindow = new Object();
var actWindowHandle = 0;

function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
    // Check if the command is in the form: /act<some spaces><nickname><some spaces><message>
    if (new RegExp(/^\/act\s*(\S*)\s*(.*)$/).exec(sMessage) != null) {
        // Store needed variables
        actNick = RegExp.$1;        // our action nick
        actMessage = RegExp.$2;    // our action message
        actWindow = oChatWnd;
        actWindowHandle = oChatWnd.Handle;

        // Check if all required parameters are filled in
        // (return "/me" is a crude trick to show the "parameter required" error)
        if (actNick === "" || actMessage === "") return "/me";

        // If we are still in a previous action process don't update the oldNick variable
        if (oldNick === "") oldNick = Messenger.MyName;
        // Change our nick
        Messenger.MyName = actNick;

        // Wait for the nick to be changed
        MsgPlus.AddTimer("pollNickChange", 100);

        return "";
    }
}

function OnEvent_Timer(sTimerId) {
    if (sTimerId === "pollNickChange") {
        if (Messenger.MyName === actNick) {
            // Nick has been changed, we are now ready to send our action message
            // Check if the chatwindow still exists(!) and if we actually can send something
            var lpClassName = Interop.Allocate(28);
            Interop.Call("User32", "GetClassNameW", actWindowHandle, lpClassName, 14);
            if (lpClassName.ReadString(0) === "IMWindowClass")
                if (actWindow.EditChangeAllowed) {
                    actWindow.SendMessage("/me " + actMessage);
                }
            // Wait for the message to be send                   
            MsgPlus.AddTimer("pollMsgChange", 1000);
        } else {
            // Nick hasn't been changed yet, check again in 100 milliseconds
            MsgPlus.AddTimer("pollNickChange", 100);
        }
    }
    if (sTimerId === "pollMsgChange") {
        // Change our nick back to what it was
        // Note: there is no clean way to check if a message has been recieved and
        //       interpreted properly by Plus! unless you also add a sniffer to this script!!!
        //       This is also the reason why this, already complex, script doesn't always work either.
        Messenger.MyName = oldNick;
        oldNick = "";
    }
}

function OnEvent_Signout(sEmail) {
    // Make sure the timers are not running when the user signs out
    // Very important to prevent name changes of other users who might sign in afterwards
    MsgPlus.CancelTimer("pollNickChange");
    MsgPlus.CancelTimer("pollMsgChange");
    oldNick = "";
}

function OnGetScriptCommands() {
    return    "<ScriptCommands>"
        +        "<Command>"
        +            "<Name>act</Name>"
        +            "<Description>Sends an action message that starts with a custom name</Description>"
        +            "<Parameters>&lt;name&gt; &lt;message&gt;</Parameters>"
        +        "</Command>"
        +    "</ScriptCommands>";
}


But still note that even this, already complex, script is still not always doing what you want!!! People can say it works nicely, but it really doesn't! I have been busy with it all day long (see posting time and this final edit time) (and discovered certain bugs in Plus! with it also) and I can safely say that doing what you want todo in a proper way so it always works is as good as impossible to do with pure scripting.

All this is an extremely good example of how something seems strait forward, but in fact is really hard (impossible) todo.

If you want something which will always work (in whatever condition it is used in; this means using the command a few times quickly (eg: quicktexts), not producing errors when the nick change limit is reached, detecting when a message is interpreted, etc), you need to deal with all this on the protocol level...


;)

.plsc File Attachment: Action Command+.plsc (2.26 KB)
This file has been downloaded 171 time(s).

This post was edited on 12-01-2006 at 07:19 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
10-23-2006 10:59 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
script command error - "Command Requiers Parameter" - by Baggins on 10-23-2006 at 12:17 AM
RE: script command error - "Command Requiers Parameter" - by deAd on 10-23-2006 at 12:24 AM
RE: script command error - "Command Requiers Parameter" - by Baggins on 10-23-2006 at 12:27 AM
RE: script command error - "Command Requiers Parameter" - by matty on 10-23-2006 at 12:47 AM
RE: script command error - "Command Requiers Parameter" - by Baggins on 10-23-2006 at 12:53 AM
RE: script command error - "Command Requiers Parameter" - by matty on 10-23-2006 at 12:57 AM
RE: script command error - "Command Requiers Parameter" - by deAd on 10-23-2006 at 01:31 AM
RE: script command error - "Command Requiers Parameter" - by CookieRevised on 10-23-2006 at 10:59 AM
RE: script command error - "Command Requiers Parameter" - by Baggins on 10-23-2006 at 08:30 PM
RE: script command error - "Command Requiers Parameter" - by foaly on 10-23-2006 at 08:35 PM
RE: script command error - "Command Requiers Parameter" - by CookieRevised on 10-23-2006 at 08:36 PM
RE: script command error - "Command Requiers Parameter" - by Baggins on 10-23-2006 at 09:00 PM
RE: RE: script command error - "Command Requiers Parameter" - by CookieRevised on 10-23-2006 at 09:24 PM
RE: RE: RE: script command error - "Command Requiers Parameter" - by Baggins on 10-23-2006 at 09:26 PM
RE: script command error - "Command Requiers Parameter" - by CookieRevised on 10-23-2006 at 09:14 PM
RE: RE: script command error - "Command Requiers Parameter" - by Baggins on 10-23-2006 at 09:21 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On