What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Curiousity with arrays (meaning, why is this happening?

Curiousity with arrays (meaning, why is this happening?
Author: Message:
Volv
Skinning Contest Winner
*****

Avatar

Posts: 1233
Reputation: 31
35 / Male / Flag
Joined: Oct 2004
RE: Curiousity with arrays (meaning, why is this happening?
This is because of the following line:
data2 = data;
What you are essentially doing is creating a reference to data in data2. So when you print data2[0] it's actually referring to data[0] and printing that.
In order to copy an array as opposed to referencing, you need to clone all the elements it contains.

EDIT: Ok, guess Mattike beat me to it with a far superior post *cough* Show off *cough* lol j/k :p

One thing I would like to point out:
quote:
Originally posted by Mattike
The error is that when you assign an array variable to a new variable, it is dependent of this original array. That is, when you change the original one, the new one follows.
I think Mattike already knows this but just expressed it ambiguously: it does not actually create a copy and then apply any changes made to the original to the new array, it only creates a reference to the original array. That is, that data2[] is essentially data[].

This post was edited on 01-10-2008 at 05:45 PM by Volv.
01-10-2008 05:39 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Curiousity with arrays (meaning, why is this happening? - by MeEtc on 01-10-2008 at 05:13 PM
RE: Curiousity with arrays (meaning, why is this happening? - by Matti on 01-10-2008 at 05:39 PM
RE: Curiousity with arrays (meaning, why is this happening? - by Volv on 01-10-2008 at 05:39 PM
RE: Curiousity with arrays (meaning, why is this happening? - by mynetx on 01-10-2008 at 07:15 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