User properties Array not correctly got
Posted: 17 Jul 2011, 14:29
Hi. The bug is that when you put an Array (array of objects in my case) in the user properties (by using user.properties.put("array", myArray), it puts the array correctly, but when i get it later (by using user.properties.get("array"), the array loses some of its properties.
In my case I was trying to concatenate one of the user properties (to get a new array and not update the one inside the properties) but, after looping through the concatenated array, i got an unexpected result, all of the content of the array from the properties was added to the first index to the concatenated array.
Here's an example code:
And here's the output:
Despite this, so far, all the other array's properties work, such as length, and looping through it works fine. I haven't tested the other Array's methods like splice, sort, etc.
As a temporary solution, i had to create a function that creates a new array from the properties one, by looping through it.
[EDIT]
Forgot to mention that the concat() function works in arrays created on server-side, only doesn't work on arrays inside the user properties.
Best regards,
rjgtav
Notes:
I'm using SFS Pro 1.6.9
In my case I was trying to concatenate one of the user properties (to get a new array and not update the one inside the properties) but, after looping through the concatenated array, i got an unexpected result, all of the content of the array from the properties was added to the first index to the concatenated array.
Here's an example code:
Code: Select all
var array1 = [1, 2, 3, 4];
user.properties.put("array", array1);
var array2 = user.properties.get("array").concat();
trace("=== Array1 ===")
trace("length: "+array1.length)
for(var i = 0; i<array1.length; i++){
trace(i+": "+array1[i]);
}
trace("=== Array2 ===")
trace("length: "+array2.length)
for(var i = 0; i<array2.length; i++){
trace(i+": "+array2[i]);
}As you can see, in this case the concat() function copies all the properties array to the first index of the new array.=== Array1 ===
length: 4
0: 1
1: 2
2: 3
3: 4
=== Array2 ===
length: 1
0: 1, 2, 3, 4
Despite this, so far, all the other array's properties work, such as length, and looping through it works fine. I haven't tested the other Array's methods like splice, sort, etc.
As a temporary solution, i had to create a function that creates a new array from the properties one, by looping through it.
[EDIT]
Forgot to mention that the concat() function works in arrays created on server-side, only doesn't work on arrays inside the user properties.
Best regards,
rjgtav
Notes:
I'm using SFS Pro 1.6.9