Closing entity gui when player moves away

Place to get help with not working mods / modding interface.
mrvn
Smart Inserter
Smart Inserter
Posts: 5925
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Closing entity gui when player moves away

Post 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?
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5290
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: Closing entity gui when player moves away

Post 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
inferis
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Nov 01, 2019 2:02 am
Contact:

Re: Closing entity gui when player moves away

Post 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.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Closing entity gui when player moves away

Post 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 ;).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
inferis
Burner Inserter
Burner Inserter
Posts: 13
Joined: Fri Nov 01, 2019 2:02 am
Contact:

Re: Closing entity gui when player moves away

Post 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
Post Reply

Return to “Modding help”