Vice City: Multiplayer
VC:MP Discussion => Support => Bugs and Crashes => Topic started by: Kenneth Law on January 28th, 2020, 10:25 AM
Let's just start with an example.
At first I defined an array
And while I changed the value of Array to 3, the value of Array was also automatically changed to 3, which is not reasonable.
I have tested a lot of times and it was proved that the value of Array always equals to that of Array no matter how I try to make them two different elements.
Here is the code which I used for test
function onPlayerCommand( player, cmd, text )
What you were doing when the bug happened
Not doing anything
What you think caused the bug
Maybe squirrel language doesn't allow the existence of two-dimensional array?
I had the same issue a long time ago and SLC explained why it occured.
reference to same array(1) is copied to every slot
so you have the same array in every slot of the host array
only fundamental types are copied. i.e. ints, floats, bools, nulls etc.
everything else is copied by reference. as usual
same applies when you create a class and have non-fundamental type members. you initialize them in the constructor instead
in official plugin with (likely) outdated squirrel, the following can be used to go around that issue.
local arr = array(5);
in sqmod, that can be reduced to a statement.
local arr = array(5).apply(@(_) array(1));
first iandisn't there a problem with indices?
gave 12. i hope this is the problem.
c <- [[0,0],[0,0]]
Thx a lot.
Now problem has been solved.
I am not sure whether you are right but I did it like this
and it works.
arr <- array(2, null);
arr = [0, 0];
arr = [0, 0];