Adding gps tags/map pings with code

Suggestions that have been added to the game.

Moderator: ickputzdirwech

Zaflis
Filter Inserter
Filter Inserter
Posts: 518
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Adding gps tags/map pings with code

Post by Zaflis »

It would be helpful for players and modders to ping a map location by script when debugging issues, or showing "relevant event locations". The alternative as it is, is to print out coordinates but you don't know where that is. Game does not show numbers on player or cursor.

It was this reddit post that raised awareness of the issue:
https://www.reddit.com/r/factorio/comme ... ific_unit/

You can print a position of entity with:

Code: Select all

/c for _, e in pairs(game.player.surface.find_entities()) do
  if e.unit_number == 353079 or e.unit_number == 352947 then
    game.print(e.position)
  end
end
But there is no command such as:

Code: Select all

game.ping(e.position)
Or to auto-include surface:

Code: Select all

game.ping(e)

Code: Select all

e.ping()
I'm not sure what you would prefer; ping(), mapping(), pingmap(), gps(). I'd take the first one as long as it doesn't confuse anything with networking.

The gps tag itself is not even defined in LUA. Also as i was typing it occured to me it might be a syntax and it is:
viewtopic.php?p=557940
However that doesn't invalidate the issue above. Not even google was able to find that information when needed, and it does not seem trivial to implement the syntax.
Last edited by Zaflis on Sun Dec 03, 2023 9:59 am, edited 1 time in total.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Adding gps tags/map pings with code

Post by Qon »

Zaflis wrote: ↑Sun Dec 03, 2023 9:16 am However that doesn't invalidate the issue above.
Why!?!?!

And, yes it does. It perfectly invalidates your whole post because it does solve exactly what you asked for. You only describe issues with not knowing how to ping locations, none of your issues are related to how the pinging is achieved.
Zaflis wrote: ↑Sun Dec 03, 2023 9:16 am Not even google was able to find that information when needed
Maybe you searched wrong. And google isn't omniscient. This doesn't prove anything.
Zaflis wrote: ↑Sun Dec 03, 2023 9:16 am and it does not seem trivial to implement the syntax.
!?!?!?!?!?
This is a "hello, world" program with string concatenation. It is literally the very first thing you learn how to do as your first step, starting from no coding experience at all. It is THE MOST trivial thing to do!
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Zaflis
Filter Inserter
Filter Inserter
Posts: 518
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: Adding gps tags/map pings with code

Post by Zaflis »

Qon wrote: ↑Sun Dec 03, 2023 9:38 amThis is a "hello, world" program with string concatenation. It is literally the very first thing you learn how to do as your first step, starting from no coding experience at all. It is THE MOST trivial thing to do!
%%% wrong with your aggression? It takes an IT professional to find that the format is:
string.format("[gps=%s,%s]", pos.x, pos.y")

It's not documented anywhere, how the * would some random dweller know how to instruct another forum poster on his issues?

Oh, that's not even adding the surface automatically if you use it for entity on some Space Exploration planet.
Last edited by Zaflis on Mon Dec 04, 2023 3:42 pm, edited 1 time in total.
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Adding gps tags/map pings with code

Post by Qon »

Zaflis wrote: ↑Sun Dec 03, 2023 9:47 am
Qon wrote: ↑Sun Dec 03, 2023 9:38 amThis is a "hello, world" program with string concatenation. It is literally the very first thing you learn how to do as your first step, starting from no coding experience at all. It is THE MOST trivial thing to do!
Wtf's wrong with your aggression?
First of, telling you that hello world is trivial is not aggression.
Zaflis wrote: ↑Sun Dec 03, 2023 9:47 am It takes an IT professional to find that the format is:
string.format("[gps=%s,%s]", pos.x, pos.y")
The string.format() function is not part of the map pinging, it's one users choice of creating the string.
The format is

Code: Select all

[gps=x,y]
or

Code: Select all

[gps=x,y,surface]
Just write it in chat with some numbers instead of x and y if you want to see it in action.
Zaflis wrote: ↑Sun Dec 03, 2023 9:47 am It's not documented anywhere,
It is easy to find on the wiki entry for rich text.

String concatenation operator in Lua is

Code: Select all

..
If you don't want to use string.format() then just do

Code: Select all

game.print("Hello, world [gps="..x..","..y.."]")
Literally a "Hello, World!" program.
Zaflis wrote: ↑Sun Dec 03, 2023 9:47 am Oh, that's not even adding the surface automatically if you use it for entity on some Space Exploration planet.
That isn't solved by a game.ping() function. Then you would have a game.ping() that also doesn't handle being on a different surface than your ping.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Zaflis
Filter Inserter
Filter Inserter
Posts: 518
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: Adding gps tags/map pings with code

Post by Zaflis »

The complexity of it is still quite something not everyone is comfortable with, and even less memorizing it. You'll almost certainly have to look for reference if you want to do it, and once you do it is still some work to adapt it to what you want to do. Aliases are important to both programmers and players. Modders would very likely wrap it in a function, but console command users cannot. Especially if it's a feature so critically useful as pinging a map, like a core feature in Factorio itself.

For modders i suppose it's something like...

Code: Select all

function pingmap(e)
  game.print("[gps="..e.position.x..","..e.position.y..","..e.surface.."]") // or e.surface.name??? See more questions and questions
end
Pi-C
Smart Inserter
Smart Inserter
Posts: 1738
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Adding gps tags/map pings with code

Post by Pi-C »

Zaflis wrote: ↑Sun Dec 03, 2023 10:42 am Modders would very likely wrap it in a function, but console command users cannot.

Code: Select all

/c a = function(x) game.print(x) end
/c a(123)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Adding gps tags/map pings with code

Post by Qon »

Zaflis wrote: ↑Sun Dec 03, 2023 10:42 am The complexity of it is still quite something not everyone is comfortable with,
It's meant to be usable even by players with no coding experience. Modders are expected to have higher technical abilities.
Zaflis wrote: ↑Sun Dec 03, 2023 10:42 am and even less memorizing it. You'll almost certainly have to look for reference if you want to do it, and once you do it is still some work to adapt it to what you want to do. Aliases are important to both programmers and players.
You would need a reference either way, both are equally memorable. And looking up a reference is not that hard and also expected when writing code. That's what it is for.
Zaflis wrote: ↑Sun Dec 03, 2023 10:42 am Modders would very likely wrap it in a function, but console command users cannot.
Wrong, console command users can wrap it in a function.
Zaflis wrote: ↑Sun Dec 03, 2023 10:42 am Especially if it's a feature so critically useful as pinging a map, like a core feature in Factorio itself.
The ping appears in chat. Rich text objects in chat are a part of messages in chat. You want a lot of unnecessary functions that removes functionality from the print functions, like differentiation between game.print(), force.print() and player.print(), and the ability to have more things than just a single ping in the message. If a mod is pinging the map in chat it's confusing for the players if the ping doesn't come with an explanation of why the mod is pinging your map.
Zaflis wrote: ↑Sun Dec 03, 2023 10:42 am For modders i suppose it's something like...

Code: Select all

function pingmap(e)
  game.print("[gps="..e.position.x..","..e.position.y..","..e.surface.."]") // or e.surface.name??? See more questions and questions
end
Yes, surface.name. Your confusion is not an argument.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Zaflis
Filter Inserter
Filter Inserter
Posts: 518
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: Adding gps tags/map pings with code

Post by Zaflis »

Qon wrote: ↑Sun Dec 03, 2023 11:18 amIt's meant to be usable even by players with no coding experience. Modders are expected to have higher technical abilities.
And i just demonstrated why the command is not very accessible to people without coding experience.
Qon wrote: ↑Sun Dec 03, 2023 11:18 amYou would need a reference either way, both are equally memorable. And looking up a reference is not that hard and also expected when writing code. That's what it is for.
Like i just said i looked for reference but i didn't find it. See for yourself:
https://www.google.com/search?q=factori ... ng+command
And i could memorize something like Ping() after seeing it once, it's trivial.
Qon wrote: ↑Sun Dec 03, 2023 11:18 am Wrong, console command users can wrap it in a function.
That even more requires a reference, and how often do you see functions given for console commands? How would it make sense for this case?
Qon wrote: ↑Sun Dec 03, 2023 11:18 am The ping appears in chat. Rich text objects in chat are a part of messages in chat. You want a lot of unnecessary functions that removes functionality from the print functions, like differentiation between game.print(), force.print() and player.print(), and the ability to have more things than just a single ping in the message. If a mod is pinging the map in chat it's confusing for the players if the ping doesn't come with an explanation of why the mod is pinging your map.
Ping and the explanation can and should be in separate message lines. But for more comprehensive use the rich text option is still there.
Qon wrote: ↑Sun Dec 03, 2023 11:18 am Yes, surface.name. Your confusion is not an argument.
Part of the point was the necessity to even make such a function when using the pings. It's an unnecessary time waste.

And why arguing over this when it is only for benefit of players and modders?
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Adding gps tags/map pings with code

Post by Qon »

Zaflis wrote: ↑Sun Dec 03, 2023 11:46 am
Qon wrote: ↑Sun Dec 03, 2023 11:18 amIt's meant to be usable even by players with no coding experience. Modders are expected to have higher technical abilities.
And i just demonstrated why the command is not very accessible to people without coding experience.
Git gud.
People without coding experience shouldn't complain about coding being too hard. They should try to learn, or just give up and not complain. You already have your pingmap() function, you wrote it, the API isn't improved by every possible use of rich text being reduced to a function with less power.

pingmap() broadcasts the message to all players. That's a decision you made. Not all users of a hypothetical pingmap() want that behavior.

Are you suggesting every rich text token, with every possible print function (on game, force, player, surface, RCON), gets it's own function?
something like surface.armor(player) so mods can "easily" print the armor (and nothing else) of 'player' to everyone on 'surface'?

Also, the rich text tokens are same syntax as phpBB codes, the codes we use to format text on this forum. If you can do that then you can use [gps=x,y] as well.
Zaflis wrote: ↑Sun Dec 03, 2023 11:46 am
Qon wrote: ↑Sun Dec 03, 2023 11:18 amYou would need a reference either way, both are equally memorable. And looking up a reference is not that hard and also expected when writing code. That's what it is for.
Like i just said i looked for reference but i didn't find it. See for yourself:
https://www.google.com/search?q=factori ... ng+command
And i could memorize something like Ping() after seeing it once, it's trivial.
The API shouldn't be made for the lowest common denominator. That will make it worse and bloated.
Zaflis wrote: ↑Sun Dec 03, 2023 11:46 am
Qon wrote: ↑Sun Dec 03, 2023 11:18 am Wrong, console command users can wrap it in a function.
That even more requires a reference, and how often do you see functions given for console commands? How would it make sense for this case?
The /c command is just Lua. If you know Lua it's obvious. If you don't know Lua of course you won't understand. Maybe make a first attempt at learning Lua before you complain about not understanding Lua?

Well, I see /c being used when I use it. I don't expect players to use it normally (but /c has nothing to do with [gps=x,y]). So I would say it's fairly common to use functions in your /c code when you want to input anything non-trivial.

I'm arguing that this is so trivial that a function would be pointless, but if you want to ping your own location to everyone just paste this into console:

Code: Select all

/c 
function pingmap(e)
  game.print("[gps="..e.position.x..","..e.position.y..","..e.surface.name.."]")
end
pingmap(game.player)
Zaflis wrote: ↑Sun Dec 03, 2023 11:46 am
Qon wrote: ↑Sun Dec 03, 2023 11:18 am The ping appears in chat. Rich text objects in chat are a part of messages in chat. You want a lot of unnecessary functions that removes functionality from the print functions, like differentiation between game.print(), force.print() and player.print(), and the ability to have more things than just a single ping in the message. If a mod is pinging the map in chat it's confusing for the players if the ping doesn't come with an explanation of why the mod is pinging your map.
Ping and the explanation can and should be in separate message lines. But for more comprehensive use the rich text option is still there.
Wrong. They should be together in the same message so that you know which explanation belongs to which coordinate.
Zaflis wrote: ↑Sun Dec 03, 2023 11:46 am
Qon wrote: ↑Sun Dec 03, 2023 11:18 am Yes, surface.name. Your confusion is not an argument.
Part of the point was the necessity to even make such a function when using the pings. It's an unnecessary time waste.

And why arguing over this when it is only for benefit of players and modders?
You are arguing for wrapping a single line of trivial code in a function that then requires a line of code to call, and adding that to the API so everyone else can be read the documentation and think "WTF did they add this specific thing that can't even be configured to be used with the correct print method and can't use any other text with it!?!?"

You want a personal API, written specifically for your own usecase. That's useless.
Zaflis wrote: ↑Sun Dec 03, 2023 11:46 am And why arguing over this when it is only for benefit of players and modders?
"Benefit", LOL.

If you are using function calls then you are a modder. How is this at all useful to players? Players don't use Lua.
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Zaflis
Filter Inserter
Filter Inserter
Posts: 518
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: Adding gps tags/map pings with code

Post by Zaflis »

Qon wrote: ↑Sun Dec 03, 2023 1:18 pm pingmap() broadcasts the message to all players. That's a decision you made. Not all users of a hypothetical pingmap() want that behavior.
There is no such command in current game, i posted few proposals for the function name that i could be. It doesn't have to be any of them.
Qon wrote: ↑Sun Dec 03, 2023 1:18 pm Are you suggesting every rich text token, with every possible print function (on game, force, player, surface, RCON), gets it's own function?
something like surface.armor(player) so mods can "easily" print the armor (and nothing else) of 'player' to everyone on 'surface'?
Are you trolling now? There is only 1 relevant thing in the current rich text page that warrants this attention. It's for one important part useful for debugging the world ingame. People generally copy whole codes as they are from wiki or something, printing out plain coordinate numbers is less hands-on-info compared to actually seeing the location of something. Why would you have to go around the hoops to do that?

You also just ignored the lack of information online about the issue. Term "GPS" generally refers to Earth satellite positioning system. Nobody would directly associate Factorio's map pings to it and specifically search for either it or "rich text". It's console commands we are dealing with.

Sure you can add pre and post text to the map ping function if you feel it's important.
player.Ping("Location here: ", " .")
Qon
Smart Inserter
Smart Inserter
Posts: 2164
Joined: Thu Mar 17, 2016 6:27 am
Contact:

Re: Adding gps tags/map pings with code

Post by Qon »

Zaflis wrote: ↑Sun Dec 03, 2023 2:24 pm
Qon wrote: ↑Sun Dec 03, 2023 1:18 pm pingmap() broadcasts the message to all players. That's a decision you made. Not all users of a hypothetical pingmap() want that behavior.
There is no such command in current game, i posted few proposals for the function name that i could be. It doesn't have to be any of them.
I referenced your function:
Zaflis wrote: ↑Sun Dec 03, 2023 10:42 am

Code: Select all

function pingmap(e)
  game.print("[gps="..e.position.x..","..e.position.y..","..e.surface.."]") // or e.surface.name??? See more questions and questions
end
Zaflis wrote: ↑Sun Dec 03, 2023 2:24 pm
Qon wrote: ↑Sun Dec 03, 2023 1:18 pm Are you suggesting every rich text token, with every possible print function (on game, force, player, surface, RCON), gets it's own function?
something like surface.armor(player) so mods can "easily" print the armor (and nothing else) of 'player' to everyone on 'surface'?
Are you trolling now? There is only 1 relevant thing in the current rich text page that warrants this attention. It's for one important part useful for debugging the world ingame. People generally copy whole codes as they are from wiki or something, printing out plain coordinate numbers is less hands-on-info compared to actually seeing the location of something. Why would you have to go around the hoops to do that?
I'm not trolling... more than you are.
And everything you want is already possible, so your argument is invalid.
Zaflis wrote: ↑Sun Dec 03, 2023 2:24 pm You also just ignored the lack of information online about the issue. Term "GPS" generally refers to Earth satellite positioning system. Nobody would directly associate Factorio's map pings to it and specifically search for either it or "rich text". It's console commands we are dealing with.
I did tell you it's on the rich text wiki entry. Stop your lies. Also, information being difficult for you to find doesn't mean we need a new API. That's just an argument for improved discoverability. The term "gps" is pretty irrelevant, your ideas of ping or pingmap etc would also have to be looked up anyways. And if you couldn't find those in the documentation even after added you would suggest a new API named after you, because you want a personal API built around you.

It's still not console commands we are talking about. Rich text chat and the Lua api are separate things from printing to chat through console.
Zaflis wrote: ↑Sun Dec 03, 2023 2:24 pm Sure you can add pre and post text to the map ping function if you feel it's important.
player.Ping("Location here: ", " .")
And what is that supposed to mean? You didn't supply a location or any entity with location except 'player' here. Is player used for location or for deciding who the text is printed to here?

player1.ping("location here:", player2, ".") would make more sense. If player1 is a player, at least it's an object with a print method.

You still don't understand that several things in the game have print methods. Or you are thinking that (all?) entities that you want to print out the location of should have a print method that can only print to all players?
My mods: Capsule Ammo | HandyHands - Automatic handcrafting | ChunkyChunks - Configurable Gridlines
Some other creations: Combinassembly Language GitHub w instructions and link to run it in your browser | 0~drain Laser
Zaflis
Filter Inserter
Filter Inserter
Posts: 518
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: Adding gps tags/map pings with code

Post by Zaflis »

Qon wrote: ↑Sun Dec 03, 2023 3:25 pmAnd what is that supposed to mean? You didn't supply a location or any entity with location except 'player' here. Is player used for location or for deciding who the text is printed to here?
The base entity prototype contains both position and surface it exists on, i'm pretty sure player inherits from entity.

But if we go along the same lines as game.print() then game.ping() makes sense also, it's not up to me to decide how developers want to use the idea with or which parameters.
Illiander42
Filter Inserter
Filter Inserter
Posts: 522
Joined: Mon Feb 05, 2018 10:01 am
Contact:

Re: Adding gps tags/map pings with code

Post by Illiander42 »

"Perfection is reached, not when there is nothing more to add, but when there is nothing more to take away."
computeraddict
Fast Inserter
Fast Inserter
Posts: 222
Joined: Sat Oct 07, 2023 6:44 am
Contact:

Re: Adding gps tags/map pings with code

Post by computeraddict »

Illiander42 wrote: ↑Sun Dec 03, 2023 9:02 pm "Perfection is reached, not when there is nothing more to add, but when there is nothing more to take away."
Counterpoint: https://en.m.wikipedia.org/wiki/Whitesp ... _language)

There's a right amount of abstraction for a given task and two directions of wrong amount. Writing a compiler? You'd better be friendly with your processor's opcodes, but you probably don't need to know the binary representation of them. Writing a website? Throw some html, Javascript, and CSS at the problem, and don't worry too much about what's under their hoods.
Illiander42
Filter Inserter
Filter Inserter
Posts: 522
Joined: Mon Feb 05, 2018 10:01 am
Contact:

Re: Adding gps tags/map pings with code

Post by Illiander42 »

computeraddict wrote: ↑Sun Dec 03, 2023 9:40 pm
Illiander42 wrote: ↑Sun Dec 03, 2023 9:02 pm "Perfection is reached, not when there is nothing more to add, but when there is nothing more to take away."
Counterpoint: https://en.m.wikipedia.org/wiki/Whitesp ... _language)

There's a right amount of abstraction for a given task and two directions of wrong amount. Writing a compiler? You'd better be friendly with your processor's opcodes, but you probably don't need to know the binary representation of them. Writing a website? Throw some html, Javascript, and CSS at the problem, and don't worry too much about what's under their hoods.
Whitespace is a terrible example for the point you're trying to make (since it actually isn't adding or removing anything, it's just switching alphanumeric characters for whitespace characters).

And that saying has a very obvious implied "and it still be usable" at the end.
computeraddict
Fast Inserter
Fast Inserter
Posts: 222
Joined: Sat Oct 07, 2023 6:44 am
Contact:

Re: Adding gps tags/map pings with code

Post by computeraddict »

Illiander42 wrote: ↑Mon Dec 04, 2023 8:31 am Whitespace is a terrible example for the point you're trying to make (since it actually isn't adding or removing anything, it's just switching alphanumeric characters for whitespace characters).

And that saying has a very obvious implied "and it still be usable" at the end.
Whitespace is still technically usable, just like punch cards and switch programming were usable. (It removes a lot of stuff you would find in the standard libraries of a modern high level language, by the way. It doesn't just remove characters from the character set.) The point I was making is that the minimally useful tool is not perfection. The tool with all and only features that have a favorable cost-benefit ratio is the perfect tool. A tool that lacks profitable features is imperfect just as a tool that has unprofitable features is imperfect.
Illiander42
Filter Inserter
Filter Inserter
Posts: 522
Joined: Mon Feb 05, 2018 10:01 am
Contact:

Re: Adding gps tags/map pings with code

Post by Illiander42 »

computeraddict wrote: ↑Mon Dec 04, 2023 9:11 am
Illiander42 wrote: ↑Mon Dec 04, 2023 8:31 am Whitespace is a terrible example for the point you're trying to make (since it actually isn't adding or removing anything, it's just switching alphanumeric characters for whitespace characters).

And that saying has a very obvious implied "and it still be usable" at the end.
Whitespace is still technically usable, just like punch cards and switch programming were usable. (It removes a lot of stuff you would find in the standard libraries of a modern high level language, by the way. It doesn't just remove characters from the character set.) The point I was making is that the minimally useful tool is not perfection. The tool with all and only features that have a favorable cost-benefit ratio is the perfect tool. A tool that lacks profitable features is imperfect just as a tool that has unprofitable features is imperfect.
Ahh, you're misunderstanding "usable" as "can be used" instead of "has high usability." (Yes, the terminology is terrible)

I wasn't contesting your point, btw, just pointing out that whitespace is a bad example for it.
Zaflis
Filter Inserter
Filter Inserter
Posts: 518
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: Adding gps tags/map pings with code

Post by Zaflis »

Scripting
- Added LuaEntity::gps_tag read.
https://lua-api.factorio.com/1.1.100/cl ... ml#gps_tag

If this is what it looks like then thank you very muchly ;)
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 3181
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Adding gps tags/map pings with code

Post by boskid »

:wink:

-- edit:

I am going to move this to "implemented" even when technically it does not match the request. Reason is that the request in original shape makes no sense as the pings storage is literally in the output console so it is tightly binding to message printing and it makes no sense to have a dedicated "ping" method which is just a limited "print". LuaEntity::gps_tag should cover most of the use cases including some crude debugging as its more functional to print gps_tag instead of printing position as it is possible to click gps tag and see the entity immediately in the center of screen.
Post Reply

Return to β€œImplemented Suggestions”