That’s not quite right.
This is the code you have before (more or less):
var EHealth = pc.createScript('eHealth');
EHealth.attributes.add('textHealth', {
type: 'entity'
});
// initialize code called once per entity
EHealth.prototype.initialize = function() {
this.textHealth = 100;
};
At the start of the initialize
, the variable this.textHealth
is referencing an object of entity type that has been assigned in the editor.
When you called:
this.textHealth = 100;
In the initialize
function, you changed the variable this.textHealth
from point to an object of entity type to now a number type with the value of 100. You lose the reference to the entity that referenced before.
Remember that Javascript is a weakly typed language so you can change a variable to reference ANY object type at any time.