Shoutbox

Need a counter for a specific contact - 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: Need a counter for a specific contact (/showthread.php?tid=86018)

Need a counter for a specific contact by chadchoud on 09-18-2008 at 08:04 PM

Well I'm checking bad words from users.

code:
times = 0;
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind)
{
    var Contacts = ChatWnd.Contacts;
    var e = new Enumerator(Contacts);
    var Contact = e.item();
    if (Message == "some bad word here") {
        times = times + 1;
        MsgPlus.DisplayToast("Look man", Origin + " sent a bad word");
        ChatWnd.SendMessage("This is your warning number: " + times);
        if (times == 1) {
            ChatWnd.SendMessage("One more time and you'll be blocked.");
        }
        else if (times >= 2) {
            Contact.Blocked = true;
        }
    }
}

Ok my problem is with the global variable. Say contact X says this bad word, then contact Y says it, Y gets blocked because times gets equal 2 at Y's message. What I need to know is if it' possible fr every contact to hold its own counter.

Sorry if my idea is a bit noob, but it will let me understand other concepts.

Thank you.
RE: Need a counter for a specific contact by MeEtc on 09-18-2008 at 08:17 PM

I would recommend using an array to hold the count data.


RE: RE: Need a counter for a specific contact by chadchoud on 09-18-2008 at 08:19 PM

quote:
Originally posted by MeEtc
I would recommend using an array to hold the count data.

Can you please explain how?
Arrays don't really exist in the MPLdocs I have (the chm file).
RE: Need a counter for a specific contact by MeEtc on 09-18-2008 at 08:30 PM

No, an array structure has nothing to do with the messenger plus documentation, its in the JScript documentation from Microsoft.
http://www.microsoft.com/downloads/details.aspx?f...BB9&displaylang=en

snippet from the docs:

quote:
Traditionally, array elements are given numeric indices, starting at zero. It is these elements that interact with the length property. Nevertheless, because all arrays are also objects, they support expando properties as well. Note, though, that expando properties do not interact with the length property in any way. For example:

// An array with three elements
var myArray = new Array(3);

// Add some data
myArray[0] = "Hello";
myArray[1] = 42;
myArray[2] = new Date(2000, 1, 1);

// This will display 3, the length of the array
window.alert(myArray.length);

// Add some expando properties
myArray.expando = "JScript!";
myArray["another Expando"] = "Windows";

// This will still display 3, since the two expando properties
// don't affect the length.
window.alert(myArray.length);

RE: Need a counter for a specific contact by chadchoud on 09-18-2008 at 08:56 PM

Fine. I created

code:
count = new Array();
outside the function then inside it I replaced times with count[Contact.Email] so that it becomes:
code:
count[Contact.Email] = count[Contact.Email] + 1;
But
code:
Debug.Trace(count[Contact.Email]);
prints:
-1.#IND

What's wrong now?

Edit: Solved. Had to check if it's != null. :)