Subscription to playerEntersPortal

Hello everyone! In general, API subscriptions are working well for me (for example playerMoves etc.), but I can’t get the playerEntersPortal subscription to trigger. If I do e.g.

game.subscribeToEvent('playerEntersPortal', (data, context) => {
console.log(data);
});

I would expect this to trigger when entering a portal. But this never triggers :thinking:
I see the subscription when checking game.subscriptions, but it is not called.

I noticed that the behaviour of portals is that the players never really “enter” a portal (I tried matching x/y coordinates of portals with playerMoves x/y) but he/she is teleported before that.

Any ideas regarding this?

What types of portals have you tried? Specifically, the difference between same-space portals and cross-space portals. If I recall correctly, the playerEntersPortal event is used more server side than accessible client side.

What are you trying to use the trigger for? There may be a work around using playerMoves and teleport.

1 Like

Thanks for the hint! Indeed, this event only triggers for portals that link to a different space! Portals to the same room or to another room in the same space will not trigger this.

I guess I will have to resort using playerMoves + teleport for my usecase.
I wanted to modify the dungeon escape map in a way that if a player enters a trap and is “reset” to the cell, the whole team (e.g. all the players wearing the same hat color) is reset too.
So my best bet is to first extract all the portals that reset players, delete the portals, and do a x/y coordinate matching on playerMoves instead.
As a different approach, I tried matching x/y coordinates to portal coordinates at playerMoves, but as mentioned above, the player never actually enters a portal but is teleported before he/she steps on it.

Hi there, sorry for the delay in responding to this. We (Gather’s Engine team) are trying to make an effort to be more present on the forums, so you’ll be seeing more of me :slight_smile:

playerEntersPortal, as Bill notes, is indeed only triggered if the portal targets a URL. Otherwise, they are processed as if they were a normal move.

For now, tracking player moves is the closest approximation of that behavior- whenever someone moves, check their position, if they are at x/y, they stepped on the portal. However, this is a noisy event to have to handle, and I agree that it’s clunky, so I have filed a ticket with the rest of the team to make this easier for you in the future - not sure when we’ll be able to get to it, but it’s on our radar now.

Thanks!

Thanks for the reply, and great that you guys are looking into this! As said before, tracking playerMoves only works if there is actually no portal, since the player never steps on the portal and is teleported before.

If the player actually would step onto a portal, we could use the portals as list of x/y coordinates, and if a playerMoves event coordinate would coincide with a coordinate of one of the portals, it would be a “poor man’s” player enters portal event :wink:

Looking foward on updates!