开发者

Multidimensional Array: Set the value of an item in it to another one

开发者 https://www.devze.com 2023-03-14 03:00 出处:网络
I have two two-dimensional arrays, and this line of code: openListParents[compWith] = openList[olID]; Does it work? Yes. However, openListParents[compWith] becomes openList[olID], but I want openLi

I have two two-dimensional arrays, and this line of code:

openListParents[compWith] = openList[olID];

Does it work? Yes. However, openListParents[compWith] becomes openList[olID], but I want openListParents[compWith] to be the value of openList[olID]. This is what 开发者_运维问答I get when I press CTRL+ALT+V:

Variable _level0.openListParents = [object #13, class 'Array'] [
0:[object #14, class 'Array'] [
  0:4,
  1:4
],
1:[object #7, class 'Array'],
2:[object #15, class 'Array'] [
  0:3,
  1:3
]

]

This is because openList might change, and I want the value of that openListParents in the array to be the value of the openList at the time when the code is run.

Thanks for any help


the problem is it is being passed by reference. what you want is a copy of the array not a reference to the array.

a quick way to do that in AS3 is to do an empty concat on the array and it will return a copy of itself with nothing added

array2 = array1.concat()
//array2 now has a copy of array1 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号