Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
-)a)(

Not a seroius bug, but ... "set"-command...

Recommended Posts

Hi,

i don't it this bug was mentioned in this forums in the past, so i will share my knowledge.

If you use the set-command on an array called "A" and you has an array "B" with exact the same content, both arrays will be changed. This bug appears even when the second array is in a local scope (with the "_" at the beginning).

Does anyone can confirm this bug? [i hope my OFP is ok ;) !]

Because the new patch was just released, so i don't have hopes that this bug will be fixed ever.

Greetz

Dax

Share this post


Link to post
Share on other sites

Yes this is a known issue by quite a few people. When you do arr1 = arr2 and the arrays are multidimensional, arr2 is basically a reference like arr1 to the same elements.

That is also why you can not do

arr1=[[1,2],[3,4]]

arr1=arr1-[1,2]

because [1,2] is basically a reference which you have no access to other than with set.

Basically you are working with pointers in OFP. Pointers that are automatically dereferenced by OFP commands.

Share this post


Link to post
Share on other sites

This is intended behaviour, see Command Refrerence, Scripting topics:

Array assignment

Assignment used on arrays assigns only pointer to the same array to the target variable. When b is an array, after executing a = b both a and b represent the same array. When b is changed, a is changed as well. One particular situation that can lead to this behaviour is aList = list sensor_name. You can force creating a copy of array by using unary operator +Array

Share this post


Link to post
Share on other sites

Thank you very much for you replies, and sorry for not reading the Comref exact, next time i should go a little bit deeper into the details. smile_o.gif

Share this post


Link to post
Share on other sites

Don't go yet, there is something else you should know:

the unary operator + will copy the array, multidimensional or not, but if your array has pointers inside of it, it will copy the pointers to those arrays (as it makes identical copy). So this will be dangerous for functions that return arrays within arrays like this;

arr1 = [1,2,3]

arr2 = [arr1,4]

arr3 = +arr2

arr1 set [2,5]

NOW

arr1 > [1,2,5]

arr2 > [arr1,4]

arr3 > [arr1,4]

dereference arr2 and arr3 (as in sidechat or access)

arr2 > [[1,2,5],4]

arr3 > [[1,2,5],4]

another problem would be if your function modifies arr3 select 0 select X, it will actually modify the array arr1 in parent function and thus arr2 in parent function would appear to change as well. (since it has pointer to arr1). smile_o.gif

Best thing to do is:

arr1 = [1,2,3]

arr2 = [+arr1,4]

arr3 = +arr2

Share this post


Link to post
Share on other sites

Thank you, it seems to me that you had much fun with the arrays during making CoC. wink_o.gif

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×