Event Emit Error

Why node.emit in not passing the data info of my event?

onCollisionEnter : function(other){
other.node.emit(“takeDamage”, {amount: 10});
}

When I receive the evento on the other object the detail paramenter is always undefined.

Do you have a test project to evaluate the issue?

TestProject.zip (220.0 KB)

For sure, here it is.

thank you

The function that will be called when the event triggers only have 1 parameter: event
The data you sent is inside “event.detail”

So your function should be:

teste: function(event){
    console.log(event.detail);
}

Check this to get a list of the event properties: http://cocos2d-x.org/docs/api-ref/creator/v1.5/classes/Event.EventCustom.html

1 Like

Even if I do that the current event.detail return undefined. Have you tried?

I have built a game around custom events.
And I have tried with your project and works great.

What version of Cocos creator are you using?

1.5.2.
But it works in all versions.

I’ve updated my versio to 1.7 and it started to work. Apparently it didnt on versio 1.6.2

Just stumbled upon this issue, in v1.6.2 CC reuses event objects, so if you keep the whole event object and access event.detail later it gets messed up by other emitted events. Thus you need to store event.detail immediately in eventListener if you plan to use it later