What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] 'undefined' is null or not an object.

[Help] 'undefined' is null or not an object.
Author: Message:
Timma
New Member
*


Posts: 5
Joined: Sep 2008
O.P. [Help] 'undefined' is null or not an object.
code:
for (i = 0; i <= textray.length; i++){
for (k = 0; k <= (textray[i] ? textray[i].length : 0); k++){
if (textray[i].substring(0,4)=="http") {
text = textray[i] + text;
}else{
text = textray[i].substring(k, k+1) + text;
}}}

Just a few things first, textray is an array formed by str.split(" ");, text is a blank predefined variable and str is the message typed in.

I get the error "'undefined' is null or not an object." on the lines with substring on them.

What I was trying to do here, if you can't see it, is reverse the words, and if a word is a link, don't reverse it. The problems only started when I began to use the array. I just used the string before.

Say if you do need more of the script. If it's easier for you, you can just rewrite the code :D
09-14-2008 04:22 AM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [Help] 'undefined' is null or not an object.
Change the <= to a = in your for() loops. That should do it. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-14-2008 01:30 PM
Profile E-Mail PM Web Find Quote Report
Timma
New Member
*


Posts: 5
Joined: Sep 2008
O.P. RE: [Help] 'undefined' is null or not an object.
Alright, I did that. And it seems to crash my MSN whenever someone sent me a message.
09-15-2008 09:31 AM
Profile E-Mail PM Find Quote Report
pollolibredegrasa
Full Member
***

Avatar
formerly fatfreechicken

Posts: 483
Reputation: 34
35 / Male / Flag
Joined: May 2005
RE: [Help] 'undefined' is null or not an object.
quote:
Originally posted by Timma
code:
for (i = 0; i <= textray.length; i++){

Change that line to either
code:
for (i = 0; i < textray.length; i++){
or
code:
for (i = 0; i <= textray.length-1; i++){

Array.length gives the number of items +1, so when it reaches this number in the loop you've come to an array item that doesn't exist, hence the 'undefined' error. At least, that's my understanding of it :P

Hope this helps :)
;p

[Image: chickennana.gif] Vaccy is my thin twin! [Image: chickennana.gif]
09-15-2008 10:34 AM
Profile PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
38 / Male / Flag
Joined: Jul 2005
RE: [Help] 'undefined' is null or not an object.
quote:
Originally posted by pollolibredegrasa
Array.length gives the number of items +1
it does not. (well, in some specific cases it does, but not in this case)

quote:
Originally posted by windows scripting documentation
As the elements in an array do not have to be contiguous, the length property is not necessarily the number of elements in the array. For example, in the following array definition, my_array.length contains 7, not 2:
code:
var my_array = new Array( );
my_array[0] = "Test";
my_array[6] = "Another Test";



Because Timma's textray is made by using string.split(), it is a contiguous array. In this case textray.length gives you the exact number of elements in the array textray.
The reason textray[textray.length] does not exist, is because the elements counter is zero-based, whereas textray.length is not.
example:
If you have a string of only one word as input, string.split(" ") will return an array (textray) with only 1 element.
this element is stored in textray[0], but textray.length will be 1.
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
09-15-2008 11:20 AM
Profile PM Find Quote Report
Timma
New Member
*


Posts: 5
Joined: Sep 2008
O.P. RE: [Help] 'undefined' is null or not an object.
So do I implement a check for if it's one word?

code:
for (i = 0; i <= textray.length-1; i++){

Or just use that code?
09-16-2008 05:51 AM
Profile E-Mail PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
38 / Male / Flag
Joined: Jul 2005
RE: [Help] 'undefined' is null or not an object.
you can use that code
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
09-16-2008 09:34 AM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


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