Ok so I’m trying to make it so when you click a key the level resets,but the code isnt working
here’s the code:
var Al = pc.createScript('Al');
//variables and scripts//
var menu = Score;
var Score = dlevel;
var dlevel = this.entity;
var reset = 'null';
Al.prototype.intalize = function() {
if(this.app.keyboard.isPressed(pc.KEY_F)) {
this.dlevel.entity.reset();
}
};
Al.prototype.reset = function() {
this.entity.findByName('dlevel',this.reset);
};
Your code seems to have several issues:
-
this.dlevel which should be just dlevel (local variable) is already a pc.Entity alas you try to access an entity property on line 11. That wouldn’t work unless you added a custom entity property on your entity manually.
-
You try to access the reset method as a property method on your entity. That wouldn’t work either, that method should be accessed on the the script context:
this.reset();
- Then on your reset method you try and call the findByName method with wrong arguments. Try reading the documentation on the pc.Entity class to learn how to do that:
https://developer.playcanvas.com/en/api/pc.Entity.html