TypeError: undefined is not an object

Hi, I’m trying to move a ‘score’ entity once a ‘Digit’ is enabled. This is so it is always centered at the top of the screen. I have tried the code below:

var app = this.app;

var Digit2 = this.entity.findByName('Digit 2');
var Digit1 = this.entity.findByName('Digit 1');
var Digit0 = this.entity.findByName('Digit 0');
if (Digit1.enabled === true) {
    Digit2.setLocalPosition(0.02, 0, 0);
    Digit1.setLocalPosition(-0.02, 0, 0);
if (Digit0.enabled === true) {
    Digit0.setLocalPosition(-0.025, 0, 0);
    Digit1.setLocalPosition(0, 0, 0);
    Digit2.setLocalPosition(0.025, 0, 0);

Doing this got the error: TypeError: undefined is not an object
Any help?

1 Like

Not really much of an expert in errors, but you may wanna try getting the entities using attributes instead. Undefined means that a variable isn’t assigned. If this doesn’t help, try reaching out to @will or @yaustar for help.

Trying to make them attributes did not work, but I appreciate the help :grinning:

1 Like

If you can provide a link to the project, that would really help users provide help.


This is Will’s project, do you have a link to your project that has the error?

Oh, sorry, I had Will’s open and copied the wrong one

I have found that there are two pairs of numbers called digit 1, digit 2, digit 3.

1 Like

The issue seems to be that the definition of the flow type for _setComponentRef not only defines the type but also initializes the value with undefined .

_setComponentRef: Function;

This is probably a babel setup error, most likely around @babel/preset-flow and/or @babel/plugin-proposal-class-properties .