Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by quidmonkey

When referencing another Entity from within a different Entity's class, I've seen the documentation use this:

var puck = ig.game.getEntitiesByType( EntityPuck )[0];

Is puck a pointer? If I change the properties of puck, is it changing the properties of the object it's referencing. If not, is there a way to reference (and change) an object directly?

Thx.

1 decade ago by fugufish

puck is an object.

try loading the Puck game, and open the javascript (error) console. type the same line of code in, and see for yourself.

1 decade ago by fugufish

i try not to think in terms of pointers ( trying to move away from the C/C++ thinking).

1 decade ago by dominic

The general rule for JavaScript is that objects are always passed by reference, while primitive types (Number, String...) are passed by value.

So, yes, the var puck is referencing the exact same object that is also in the game&039;s #.entities array. It's not a copy.
Page 1 of 1
« first « previous next › last »