What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Replacing Words from an Array

Replacing Words from an Array
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Replacing Words from an Array
ChatWnd.EditText is the text currently being typed by the user. Because you're using the OnEvent_ChatWndSendMessage, this will be empty as the message is already about to be sent and therefore the input area has been cleared. To change the message to be sent, you need to return the modified message at the end of your function.

Also, your replacing won't work either. First, you replace "hi" with "sfe" and store it in EditText. Then, you replace "hey" with "wagwan" in the original message and overwrite EditText, resulting in the first replacing being lost! In the end, you'll end up with only "helo" being replaced by "oi". A very simple solution is by saving the replacement result in the same variable as the one used for the replacing, which is "Message".

So, a fix for your code could be the following:
code:
function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{   
    var Greet1 = new Array();
    Greet1[0] = "hi";
    Greet1[1] = "hey";
    Greet1[2] = "hello";
    Greet1[3] = "helo";
   
    var Greet2 = new Array();
    Greet2[0] = "sfe";
    Greet2[1] = "wagwan";
    Greet2[2] = "yo"
    Greet2[3] = "oi"   

    // No need to declare variable x twice

    for (var x=0; x<4; x++)
    {
        Message = Message.replace(Greet1[x], Greet2[x]);
    }

    return Message;
}
Have a look at the changes and the explanation and make sure you understand what went wrong, so you can learn from it and won't make the same mistake again. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
12-31-2008 09:29 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Replacing Words from an Array - by KooKas on 12-31-2008 at 07:18 AM
RE: Replacing Words from an Array - by Matti on 12-31-2008 at 09:29 AM
RE: Replacing Words from an Array - by KooKas on 12-31-2008 at 12:09 PM
RE: Replacing Words from an Array - by matty on 12-31-2008 at 03:21 PM
RE: Replacing Words from an Array - by KooKas on 12-31-2008 at 11:06 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