Round floating point to integer

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.

ya but if you look here
it seems to work just fine for me

That’s because you are no longer assigning a number type to this.textHealth. You are assigning now it this.textHealth.element.text which also has issues that you can’t see.

I’m telling you the mistake you did before on this post Round floating point to integer so you can try to understand why it went wrong.

yes i see it i feel stupid for knowing why i did that but i guess i wasnt really thinking. but i looked through some things that involved text and i seen what i did wrong and thanks to your help i got it correct :slight_smile:

A post was split to a new topic: lookAt API question