[SOLVED] Is there anything wrong with my code?

var Trigger = pc.createScript('trigger');

// initialize code called once per entity
Trigger.prototype.initialize = function() {
    this.entity.collision.on('teli', this.onTriggerEnter, this);

Trigger.prototype.onTriggerEnter = function(entity) {
    // get asset by id
var asset = app.assets.get(10);
// create a slot and play it
this.entity.sound.addSlot('buzz', {
    asset: asset

Hi @the_amazing_ella! If this is your full code you are missing some closing brackets at the end. Do you have an error or is something not working?

it doesint say any errors but when i load it it says that there is an error here [trigger.js?id=46872629&branchId=3e255723-724e-4c29-9159-d1b0eb247629:5]: Cannot read property ‘on’ of undefined

TypeError: Cannot read property ‘on’ of undefined
at scriptType.Trigger.initialize (https://launch.playcanvas.com/api/assets/files/Scripts/trigger.js?id=46872629&branchId=3e255723-724e-4c29-9159-d1b0eb247629:5:27)
at ScriptComponent._scriptMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:60810:19)
at ScriptComponent._onInitialize (https://code.playcanvas.com/playcanvas-stable.dbg.js:60835:34)
at ScriptComponentSystem._callComponentMethod (https://code.playcanvas.com/playcanvas-stable.dbg.js:61424:49)
at ScriptComponentSystem._onInitialize (https://code.playcanvas.com/playcanvas-stable.dbg.js:61433:9)
at Function._helper (https://code.playcanvas.com/playcanvas-stable.dbg.js:41059:12)
at Function.initialize (https://code.playcanvas.com/playcanvas-stable.dbg.js:41064:9)
at Application.start (https://code.playcanvas.com/playcanvas-stable.dbg.js:67697:20)
at https://launch.playcanvas.com/editor/scene/js/launch.js:7397:25
at Application._preloadScripts (https://code.playcanvas.com/playcanvas-stable.dbg.js:67436:5)

Possible reasons:

  • Your script is missing some closing brackets

  • Your entity has no collision component

  • Your event name ‘teli’ has to be ‘triggerenter’

1 Like

oh ok but i just got rid of it all together i really dont need it anymore and it wont let me delete this post