Hi everyone. Thanks in advance for taking the time to read my question.
[SIZE=2]Note: All arrays are multi-dimensional.
[/SIZE]
I have some code in a function, and it is meant to take an item from the Items array, push it to the end of the **backPack **array, and then assign that backPack item a new Position element from the BPPosition array; all items in the Items array have an initial Position value of 0.
The problem is that whenever I run this function, it changes the Position value of the item in the Items array, not just the backPack array like it’s meant to. I have traced the issue back to these lines of code within the function.
newitem = backPack.push(Items[itemToAdd]); //itemToAdd is a function param that is used to pass an item code
backPack[newitem-1][Position] = BPPosition[checkBP][BPPos]; // checkBP is the init of a for loop that checks for free positions in the BPPosition array
If I trace the Items array before the first line, and then after the second line, I get this:
Brick,melee,equip,A solid and heavy construction brick.,1,1,0
[2 code lines from above]
Brick,melee,equip,A solid and heavy construction brick.,1,1,1
As you can see, the number at the end is changed - this is the initial Position element. Why on earth would it be altering my Items array? I am at an absolute loss. Any and all suggestions/help would be much appreciated!
Thanks again for your time.
Brendan