Problems with custom_entity:on_interaction()

Started by Diarandor, August 19, 2015, 04:12:58 PM

Previous topic - Next topic
Hi, I am trying to use the event custom_entity:on_interaction(), but nothing happens. I put a sound inside the event but it is not played when I press action command facing the custom entity. I have tried with traversable and non-traversable custom entities. I am aware that this was in the list of fixed bugs in version 1.2.1, so maybe I am doing something wrong (but it still could be a bug).

Also, since the hud does not show any dialog when the hero is facing the custom entity (which is probably intended since the action is not neccesary "talking", it could be anything, so I suppose that the engine does not change the effect of the action command), it would be nice to have a function to notify the hud that the event custom_entity:on_interaction() can be activated. This could be done with an event called "custom_entity:on_interaction_possible()", which is called when the hero can interact with the custom entity.

I point out that using collision tests to notify the hud that the hero can interact with the custom entity would not be perfect, since the test would not be the same that the engine uses, so it could happen that the hud is notified when the interaction is not possible or that the hud is not notified when interaction is possible.

PS: I have created two issues on Github:
https://github.com/christopho/solarus/issues/741
https://github.com/christopho/solarus/issues/742
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

For other people interested, both questions are solved, see the discussions on github.

I put a summary of the conclussions I got and a possible solution for my problem:

There is no bug. The problem was that, in the event game:on_command_pressed(command), I was defining an action which is activated when the action effect is nil, which was obstructing the event custom_entity:on_interaction() since it does not change the action effect. Also, Christopho told me that the test for the on_interaction() event is the same that for the collision test of type "facing", so no new method is needed.

A solution for my problem would be the following. First, we use a collision test of type "facing", which notifies the hud by changing some custom action effect variable. (This action effect should be restored to nil when necessary, if the hero stops facing the entity, which can be done using a timer.) Then, in the custom action effect variable we have the info that this interaction can be started, which can be used in the event game:on_command_pressed(command) to start this action instead of the predefined one for the case when there is no action effect defined by the engine.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

August 19, 2015, 10:50:01 PM #3 Last Edit: August 19, 2015, 11:56:28 PM by Diarandor
I have now realized that, if you start a timer inside a collision test, then the collision test cannot be called again until the timer stops. (Or maybe I did something wrong...) Is this intended? Does this mean that we need to wait the callback to finish until we can activate again the collision test?

Edit: I found that was caused by a silly thing of my script...  :D There is no problem with the collision tests.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."