JS pass by reference?

tested in: http://codecombat.com/play/level/quicksort-the-spiral
possible related with: https://github.com/codecombat/aether/issues/48 ?

Symptoms: after changing an element to 17, inspecting element 17 returns correctly 17, but the array print (this.debug) prints -1

you can copy and paste this code in to the mentioned code combat level.

var tree = [];
for(var i=0; i < 49; i++)
tree[i] = -1;

tree[49] = 49;
tree[50] = 50;

this.testFunction = function(tree)
tree[17] = 17;
this.debug("Tree entry 17 = "+tree[17],tree);


for(i=0;i<51; i++)
this.debug(“array[”+i+"] = "+ tree[i]);

Seems like fixing https://github.com/codecombat/codecombat/issues/1533 would also help in this case, because we wouldn’t be messing with your tree array, you having created it yourself.

It seems that your API protection is overly protective.

Might it not be better to do no protection at all, but instead slice all the this.data for each player on each call?
and keep the originals private?
Or probably more efficient just generate 2 or 3 sets (one for each player, and one private) and keeps these up to date. Then a player can set the health of its enemy to -1 but it will have no effect.

Not sure if its still possible, but we could add our own properties to the shared objects (very useful to keep track of think’s over multiple calls/turns in the relevant objects) however this also allows for exploits vs specific players, if you see the enemy using custom properties, you can set them to, i don’t know, 0 on each call to disrupt the enemy.
Creating copies as described above would avoid this exploit as well.

Easy for me to say all this without any knowledge of how the system works :smiley:

I like your thinking! I once thought this way. But as it turns out, everything that the API protection does beyond the system you just described is a response to said system (which we started with) not working well enough.