Shoutbox

[Help] 'undefined' is null or not an object. - 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] 'undefined' is null or not an object. (/showthread.php?tid=85929)

[Help] 'undefined' is null or not an object. by Timma on 09-14-2008 at 04:22 AM

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
RE: [Help] 'undefined' is null or not an object. by Matti on 09-14-2008 at 01:30 PM

Change the <= to a = in your for() loops. That should do it. ;)


RE: [Help] 'undefined' is null or not an object. by Timma on 09-15-2008 at 09:31 AM

Alright, I did that. And it seems to crash my MSN whenever someone sent me a message.


RE: [Help] 'undefined' is null or not an object. by pollolibredegrasa on 09-15-2008 at 10:34 AM

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 :)
RE: [Help] 'undefined' is null or not an object. by Jesus on 09-15-2008 at 11:20 AM

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.
RE: [Help] 'undefined' is null or not an object. by Timma on 09-16-2008 at 05:51 AM

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?
RE: [Help] 'undefined' is null or not an object. by Jesus on 09-16-2008 at 09:34 AM

you can use that code