Need help with addEvent Listener

0 favourites
  • 5 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi,

    i have the following code in which I define a class:

    runtime.globalVars.class_Axt = class axt {

    constructor() {

    this.name = "Axe"

    this.MapObject = 0

    this.ziel_person = 0

    }

    ausruesten(ziel_person) {

    this.ziel_person = ziel_person;

    this.ziel_person.onHand = this;

    this.MapObject = runtime.objects.Axt.createInstance("Items", this.ziel_person.MapObject.x, this.ziel_person.MapObject.y, false);

    this.MapObject.addEventListener("tick", this.mapObject_moveto);

    }

    mapObject_moveto() {

    this.MapObject.x = this.ziel_person.MapObject.x;

    this.MapObject.y = this.ziel_person.MapObject.y;

    }

    }

    Then I create objects and use the method ausruesten:

    runtime.globalVars.a = new runtime.globalVars.class_Axt();

    runtime.globalVars.max = new runtime.globalVars.class_Person(runtime.objects.MainPlayer.getFirstInstance());

    runtime.globalVars.a.ausruesten(runtime.globalVars.max);

    Everything works as intended except the addEventListener in ausruesten method. Im not sure whats wrong. I tested it a lot but the event is never triggering. Can someone help me and explain how it could work and why?

    Tagged:

  • Instances don't have a "tick" event.

  • Thanks, good to know.

    But why is not an error message appearing?

    And i changed the code so that the "tick" event is defined for the object class:

    runtime.objects.Axt.addEventListener("tick", runtime.globalVars.class_Axt.mapObject_moveto)

    But still it isnt working. The event does not trigger. I put an alert in the static function runtime.globalVars.class_Axt.mapObject_moveto. Is there a better way to test or debug whether events trigger?

  • If you use thing.addEventListener("tick", callback), then the callback will only run if thing fires an event named "tick". Otherwise, nothing happens.

    Check the documentation for which objects fire which events. In Construct, "tick" is only fired by runtime.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Oh okay. I understand. Thank you so much. I had the wrong understanding.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)