Hi @Leonidas, Hi @LeXXik
I need some help on using the event listener functionality. I am triggering an event from the clipper called âUI:hairCutArrayâ and listening from the game.js script which is the core script in the root. I would like to pass this.userCut array from the clipper object to the game object and do some array comparison with the standard haircut array in the game.js where this.mohawk is an array.
how do I get access to this userCut argument passed by the clipper in the game object.
var Clipper = pc.createScript('clipper');
// initialize code called once per entity
Clipper.prototype.initialize = function(){
this.userCut = [];
this.app.on("ui:hairCutDone", this.hairCutDone, this);
this.entity.collision.on('triggerenter', (other) => {
this.userCut.push(other.name);
other.destroy();
});
};
Clipper.prototype.hairCutDone = function(){
this.app.fire('ui:hairCutArray', this.userCut);
};
This event listener script in the Game object has the following codes.
Game.prototype.initialize = function() {
this.score = 0;
//Standard haircuts
this.mohawk = ['LowerNape2_Right_Collision', 'UpperNape2_Right_Collision', 'OccipitalBone1_right_Collision', 'UpperNape3_Right_Collision', 'Side_Right_Collision', 'Temple_Right_Collision', 'ParietalRidge1_right_Collision', 'ParietalRidge3_right_Collision', 'ParietalRidge2_right_Collision', 'ParietalRidge4_Right_Collision', 'LowerNape2_left_Collision', 'UpperNape2_Left_Collision', 'OccipitalBone1_left_collision', 'ParietalRidge4_left_Collision', 'LowerNape3_left_Collision', 'UpperNape3_left_collision', 'Side_Left_Collision', 'ParietalRidge2_Left_Collision', 'Temple_left_collision', 'ParietalRidge1_Left_collision', 'ParietalRidge3_left_Collision'];
// listen to events from the UI
//Scoring comparison
this.app.on("ui:hairCutArray", function (){
for (let i = 0; i < userCut.length; i++){
if (mohawk.includes(userCut[i])){
this.score += 1;
}
}
this.score -= Math.abs(this.mohawk.length - userCut.length);
console.log(this.score);
}, this);
};