Arrays and Autoreadonly questions

Post » Mon Jun 18, 2012 11:39 am

Regarding arrays, how does array assignment work? If I have the following code:

int[] array1 = new int[12]; initialize array1's valuesint[] array2 = new int[6]; initialize array2's valuesarray1 = array2

what happens? Does array1 now refer to the same array as array 2? Or are does array1 now point to a new array the same size as array2, with array2's values in it? If that's the case, was array1's original array properly destroyed? Or are array2's values copied into array1's elements?

Or the following:

float[] myArrayfloat[] Property myArrayProperty   float[] function get()      return myArray   endFunctionendProperty

If another script has "OtherScript.myArrayProperty[2] = 3.0" is myArray changed?


As for autoreadonly, are autoreadonly properties treated like constants, or are their values saved into savegames? If I have "float Property myFloat = 2.0 autoreadonly", then in a subsequent update of my mod, change the value from 2.0 to 3.0, will myFloat now return 3.0, or will it return 2.0 since that value was saved into the user's game?
User avatar
steve brewin
 
Posts: 3411
Joined: Thu Jun 21, 2007 7:17 am

Post » Mon Jun 18, 2012 11:04 am

I haven't yet delved into arrays but I'm not sure if the assignment
array1 = array2
is legal as they are different sizes. You may have to do a loop to individually copy the elements.

Why don't you set up a series of debug messages and figure it out, then let us all know! lol
User avatar
JAY
 
Posts: 3433
Joined: Fri Sep 14, 2007 6:17 am

Post » Mon Jun 18, 2012 3:05 pm

Ok, I looked at the arrays wiki page again, arrays are apparently passed by reference (hopefully with garbage collection?). So in the first example, array1 would point to the same array as array2, so changes made to array1's elements would be reflected in array2. In the second example, making changes to myArrayProperty would change myArray, since its pointing to the same thing myArray is.
User avatar
GRAEME
 
Posts: 3363
Joined: Sat May 19, 2007 2:48 am

Post » Mon Jun 18, 2012 2:31 pm

As for the autoreadonly question, the values are not stored with the save, so they'll update properly if you change them in a mod update. Good news there.
User avatar
Allison Sizemore
 
Posts: 3492
Joined: Wed Jul 19, 2006 6:09 am


Return to V - Skyrim