Hello, all.
I have a script that when when it gets a fire, it plays and animation by setting a boolean to true, and stops it on another fire by setting the boolean to false. Thats what its supposed to do.
var IcelitRecorderMask = pc.createScript('icelitRecorderMask');
IcelitRecorderMask.attributes.add('player',{type:'entity'});
// initialize code called once per entity
IcelitRecorderMask.prototype.initialize = function() {
///Events
const p1moveTrue = function(){
this.entity.anim.setBoolean('P1Move', true);
};
const p1moveFalse = function(){
this.entity.anim.setBoolean('P1Move', false);
};
//Listen + destroy Events
this.app.on('Anim:P1Move-True',p1moveTrue);
this.on('destroy', function() {
this.app.off('Anim:P1Move-True', p1moveTrue);
});
this.app.on('Anim:P1Move-False', p1moveFalse);
this.on('destroy', function() {
this.app.off('Anim:P1Move-False', p1moveFalse);
});
};
// update code called every frame
IcelitRecorderMask.prototype.update = function(dt) {
this.entity.lookAt(this.player.getPosition().x,this.player.getPosition().y,this.player.getPosition().z);
};
// uncomment the swap method to enable hot-reloading for this script
// update the method body to copy state from the old instance
// IcelitRecorderMask.prototype.swap = function(old) { };
// learn more about scripting here:
// https://developer.playcanvas.com/user-manual/scripting/
The fires are firing, but there error is on line 8. Here is the error I get: [icelitRecorderMask.js?id=204057013&branchId=eac69c03-02df-4539-ad25-d27acd4e91a1:8]: Cannot read properties of undefined (reading ‘anim’)
TypeError: Cannot read properties of undefined (reading ‘anim’)
at AppBase.p1moveTrue (https://launch.playcanvas.com/api/assets/files/icelitRecorderMask.js?id=204057013&branchId=eac69c03-02df-4539-ad25-d27acd4e91a1:8:13)
at AppBase.fire (https://code.playcanvas.com/playcanvas-1.74.0.js:859:18)
at Dummy.update (https://launch.playcanvas.com/api/assets/files/IcelitRecorderBossfligjt.js?id=203140088&branchId=eac69c03-02df-4539-ad25-d27acd4e91a1:50:12)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-1.74.0.js:65909:18)
at ScriptComponent._onUpdate (https://code.playcanvas.com/playcanvas-1.74.0.js:65935:11)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-1.74.0.js:66416:49)
at ScriptComponentSystem._onUpdate (https://code.playcanvas.com/playcanvas-1.74.0.js:66428:9)
at ComponentSystemRegistry.fire (https://code.playcanvas.com/playcanvas-1.74.0.js:859:18)
at AppBase.update (https://code.playcanvas.com/playcanvas-1.74.0.js:41149:17)
at AppBase.tick (https://code.playcanvas.com/playcanvas-1.74.0.js:41657:17)
I have the anim component on the entity with the script, I cant find whats wrong.
Project editor: PlayCanvas | HTML5 Game Engine
Scene: “glacius”
I am grateful for any help.