[SOLVED] Ok so I have a bug I need help with

Ok so I did this `var re = pc.createScript(‘re’);

re.attributes.add(“rpoint”, { type: ‘entity’, title: ‘Respawn Point’ });
// initialize code called once per entity
re.prototype.initialize = function() {

};

// update code called every frame
re.prototype.update = function(dt) {
if (this.app.keyboard.wasPressed(pc.KEY_R)) {
this.entity.findByName(‘Ball’);
this.entity.findByName(‘Ball’,this.reset);
console.log(‘Ball sholuld reset’);
this.reset();
}
};
`
To try to make the ball reset the its current positive but this keeps popping up and the code is already a function.

Look for the script named re

Btw heres the link to the editor:PlayCanvas | HTML5 Game Engine

1 Like

The error says, this.reset is not a function. You didn’t add a reset function. You need to add something like this:

ScriptName.prototype.reset = function() {
    //Reset Code Goes Here
};

[PROBLEM HAS BEEN SOLVED]

New Script:

var re = pc.createScript('re');

re.attributes.add("rpoint", { type: 'entity', title: 'Respawn Point' });        
re.attributes.add("ball", { type: 'entity', title: 'Ball' });

// initialize code called once per entity
re.prototype.initialize = function() {
   
};

// update code called every frame
re.prototype.update = function(dt) {
 if (this.app.keyboard.wasPressed(pc.KEY_R)) {
        this.reset();
    }
};

re.prototype.reset = function() {
    this.ball.rigidbody.teleport(this.rpoint.getPosition());
    this.ball.rigidbody.linearVelocity = pc.Vec3.ZERO;
    this.ball.rigidbody.angularVelocity = pc.Vec3.ZERO;
};
// swap method called for script hot-reloading
// inherit your script state here
// Redo.prototype.swap = function(old) { };

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