Error with enabled undefined?!

Ok so heres the error:


And here’s the code:

var Defbutton = pc.createScript('defbutton');

//Scenes
Defbutton.attributes.add("title", { type: 'entity', title: 'Title' });
Defbutton.attributes.add("level", { type: 'entity', title: 'Level' });
Defbutton.attributes.add("level2", { type: 'entity', title: 'Level Canvas' });
Defbutton.attributes.add("dlevel", { type: 'entity' });
Defbutton.attributes.add("result", { type: 'entity' });

//Buttons
Defbutton.attributes.add("rb", { type: 'entity', title: 'Retry Button' });

//ScoreSystem

Defbutton.attributes.add("one", { type: 'entity', title: '1' });
Defbutton.attributes.add("two", { type: 'entity', title: '2' });
Defbutton.attributes.add("three", { type: 'entity', title: '3' });
Defbutton.attributes.add("four", { type: 'entity', title: '4' });
Defbutton.attributes.add("five", { type: 'entity', title: '5' });
Defbutton.attributes.add("six", { type: 'entity', title: '6' });
Defbutton.attributes.add("seven", { type: 'entity', title: '7' });
Defbutton.attributes.add("eight", { type: 'entity', title: '8' });
Defbutton.attributes.add("nine", { type: 'entity', title: '9' });
Defbutton.attributes.add("ten", { type: 'entity', title: '10' });
Defbutton.attributes.add("eleven", { type: 'entity', title: '11' });

// initialize code called once per entity
Defbutton.prototype.initialize = function() {
    this.entity.element.on('mouseenter', this.onEnter, this);
    this.entity.element.on('mouseleave', this.onLeave, this);
    this.rb.element.on('click', this.onClickrb, this);
};

// update code called every frame
Defbutton.prototype.update = function(dt) {
    
};

Defbutton.prototype.onEnter = function(event) {
    document.body.style.cursor = 'pointer';  
};

Defbutton.prototype.onLeave = function(event) {
    document.body.style.cursor = 'default';  
};

Defbutton.prototype.onClickrb = function(e) {
    this.title.enabled = false;
    this.level.enabled = true;
    this.level2.enabled = true;
    this.dlevel.enabled = true;
    this.result.enabled = false;  
    this.resetnum();
};

Defbutton.prototype.resetnum = function() {
    this.one.enabled = false;
    this.two.enabled = false;
    this.three.enabled = false;
    this.four.enabled = false;
    this.five.enabled = false;
    this.six.enabled = false;
    this.seven.enabled = false;
    this.eight.enabled = false;
    this.nine.enabled = false;
    this.ten.enabled = false; 
    this.eleven.enabled = false;
};

// swap method called for script hot-reloading
// inherit your script state here
// Defbutton.prototype.swap = function(old) { };

// to learn more about script anatomy, please read:
// http://developer.playcanvas.com/en/user-manual/scripting/

So I keep getting that same error after the ball goes to its result screen
Any ideas why?

this.one.enabled = false;

You will have to make sure that an entity is referenced in that editor property where the script is used. And also that you aren’t removing that reference anywhere else in your code.

Well I’m kinda confused
Here’s the code editor link:https://playcanvas.com/editor/code/624824?tabs=21805247,24799274

You are missing a reference to the defbutton.js script in the editor (property name 1). If you fix that the error disappears:

Ok so it’s likes the number s overlap after the result screen,also the numbers don’t restart back to zero they stay at the current number before the result screen.Any reason why?

Not sure about that, it seems that when you restart the game the entities aren’t properly reset to their initial state (enabled/position).

I see that you reference the number entities in two scripts ScoreSystem (2).js and the defbutton.js, maybe there is a conflict in your logic?

Hmm may have to do some rescripting but may take a while or I may have to reset all the score entities and redo them one by one

1 Like

aha I found the problem so the numbers do reset but the score before the result screen stays for some unsual reason must be a bug but idk I’m gonna ask will or someone about this

1 Like