LuaPlayer :: create_local_flying_text at cursor position

Post Reply
User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 452
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

LuaPlayer :: create_local_flying_text at cursor position

Post by raiguard »

In the vanilla GUI, flying text is used to convey errors:

Image

There is no way AFAIK for us modders to do the same. Matching vanilla behavior as closely as possible is something I strive to do with my mods, and being able to create "error" texts like this would be very nice.

The simplest way to do this that I can think of would be to add an argument to player.create_local_flying_text to create it at the cursor position instead of on the map. Something like this:

Code: Select all

player.create_local_flying_text{
  text = {'fe-gui-search.no-recipes-as-ingredient-error'},
  create_at_cursor = true
}
The create_at_cursor argument would replace position in this case.

Is this something that can be done?
Don't forget, you're here forever.

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by Honktown »

You can't get cursor position, but you could center flying text at the position of the button that produced the bad action. If it's on map, use the cursor selected property or entity (player.selected.position, entity.position), etc.
I have mods! I guess!
Link

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by PyroFire »

Honktown wrote:
Sat Dec 28, 2019 5:17 pm
You can't get cursor position
That's why this is a modding interface request.

Seems fairly reasonable.

+1

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 452
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by raiguard »

You can't read cursor position, but you can tell the game to put something at the cursor position. If you could read cursor position, things would be very interesting, but that's never going to happen.
Don't forget, you're here forever.

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by Honktown »

Raiguard wrote:
Sat Dec 28, 2019 5:31 pm
You can't read cursor position, but you can tell the game to put something at the cursor position. If you could read cursor position, things would be very interesting, but that's never going to happen.
Eh? how pls
I have mods! I guess!
Link

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 452
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by raiguard »

Cursor position is not part of the gamestate (the part of the game that is deterministic). Mods run completely in gamestate, and so anything that's not deterministic cannot be read through the API. However, in a few circumstances, mods can interact with things outside of gamestate by writing them. One of these write-only properties is the width and height of a LuaGuiElement.

player.create_local_flying_text() creates the flying text outside of gamestate, so it's entirely possible for the game to attach it to the mouse cursor (or maybe a LuaGuiElement) instead of a place on the map.

If we wanted to be able to read cursor position, it would need to be added to the gamestate, which would mean sending a network packet every time the player's cursor moves even a single pixel. That would bloat network traffic in multiplayer to the extreme, which is why it will never happen.
Don't forget, you're here forever.

KingIonTrueLove
Inserter
Inserter
Posts: 23
Joined: Sun Jun 04, 2017 1:38 am
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by KingIonTrueLove »

+1
I could use this as well for one of my mods. Matching vanilla behavior is a great reason to have such a thing.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by Rseding91 »

Ok, I added it for the next release.
If you want to get ahold of me I'm almost always on Discord.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by eradicator »

Thank you very 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.

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 452
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: LuaPlayer :: create_local_flying_text at cursor position

Post by raiguard »

Thank you!
Don't forget, you're here forever.

Post Reply

Return to “Implemented mod requests”