Page 1 of 1

Closing entity gui when player moves away

Posted: Mon Sep 02, 2019 3:28 pm
by mrvn
I'm opening a custom gui for a constant-combinator type entity in on_gui_opened. But when the player walks out of reach the gui stays open.

How can I automatically close the gui when the player moves out of reach?

Re: Closing entity gui when player moves away

Posted: Mon Sep 02, 2019 3:31 pm
by Klonan
AFAIK It cannot be done automatically with the current features

You would need to check the distance yourself and determine if it is out of range

Re: Closing entity gui when player moves away

Posted: Fri Nov 01, 2019 2:25 am
by inferis
There's

Code: Select all

[url=https://lua-api.factorio.com/latest/events.html#on_player_changed_position]on_player_changed_position[/url]
and

Code: Select all

[url=https://lua-api.factorio.com/latest/events.html#on_player_changed_surface]on_player_changed_surface[/url]
.

The refresh rate at which the first is called is not very high, but it should do the trick.

Re: Closing entity gui when player moves away

Posted: Sat Nov 02, 2019 11:39 pm
by eradicator
inferis wrote: Fri Nov 01, 2019 2:25 am The refresh rate at which the first is called is not very high, but it should do the trick.
The "refresh rate" of on_changed_position are the tile boundaries. If that's "not very high"...why are you moving inside a single tile so much ;).

Re: Closing entity gui when player moves away

Posted: Sun Nov 03, 2019 1:43 am
by inferis
eradicator wrote: Sat Nov 02, 2019 11:39 pm
inferis wrote: Fri Nov 01, 2019 2:25 am The refresh rate at which the first is called is not very high, but it should do the trick.
The "refresh rate" of on_changed_position are the tile boundaries. If that's "not very high"...why are you moving inside a single tile so much ;).
Well of course, that makes sense. :D