Help with very small script - 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: Help with very small script (/showthread.php?tid=94126) Help with very small script by Barathrum on 03-17-2010 at 09:33 PM
Hello, I'm in need of a small script: RE: Help with very small script by matty on 03-18-2010 at 12:29 AM
Something like this? js code: RE: Help with very small script by Barathrum on 03-18-2010 at 05:16 PM
Well I typed this RE: Help with very small script by Spunky on 03-18-2010 at 05:26 PM
Remove the comma (,) at the end of this line js code: It should be: js code: It is a symbol used to separate multiple array items. As it is there, the array expects another item and fails when it doesn't find it. As that line of code fails, it would either cause an error and stop, or the code that does run would never find the array item. RE: Help with very small script by Barathrum on 03-18-2010 at 08:12 PM It still didn't change his messege :/ RE: Help with very small script by matty on 03-18-2010 at 08:27 PM
OOPS!!!!!!!!!!!!!!!!!! js code: By using oEmail alone it is returning the position in the Array (in other words 0). Need to use oEmails[oEmail] to get the email address from the array. RE: Help with very small script by Barathrum on 03-18-2010 at 09:06 PM
Now it works, but it sets messege for all to ' ' instead for only the email I set. RE: Help with very small script by Matti on 03-18-2010 at 09:16 PM
quote:That's exactly why I'd suggest you to stop using such variable names in loops. By naming your iterating variable "oEmail", you'd think that it contains the e-mail address as a string while actually it's just an index. A much more logical name would be something like "nEmail" or "iEmail" or just something as simple as "i". Also, when you're dealing with arrays, it's much more effective to iterate with an incrementing number over the array length instead of using property enumeration. Looping over properties is fine for plain objects, but for arrays a generic for-loop from 0 to length is much faster. Another thing I noticed is that you're checking the amount of contacts on every iteration. This is completely unnecessary and can easily be moved to the top of the function as preliminary check before the actual loop. My suggestions: js code:If you really care about speed and performance, you could even use the high-speed reverse while-loop! js code:Now, this was already pretty fast, but we can go even faster. Instead of bothering the script engine with a call to GetContact() every time, we can first retrieve the e-mail address we're looking for and then compare the e-mail addresses as a string. js code:For more information about array loops and performance in JavaScript/JScript, have a look at this article on Ajaxian. quote:Hmm, that's pretty odd. Could you try the code snippets above and see if those do any better? (I don't have time to test these myself at the moment.) RE: Help with very small script by CookieRevised on 03-19-2010 at 11:22 AM
* CookieRevised slaps both matti and matty quote: RE: Help with very small script by Barathrum on 03-19-2010 at 01:31 PM Exactly, and the above still changed the messege for both to ' ' RE: Help with very small script by markee on 05-21-2010 at 01:59 PM
So that you have a working script... JScript code: |