Ability to iterate entity properties

Things that we aren't going to implement
Post Reply
User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Ability to iterate entity properties

Post by aubergine18 »

It would be extremely useful if we could iterate the properties of an entity on map, to discover what properties it has (including undocumented stuff) and what their current values are (for debugging).

I was hoping this would be a simple case of passing an entity to serpent.dump() and log() the results, but just get back a __self property that points to userdata.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

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

Re: Ability to iterate entity properties

Post by Rseding91 »

All of the properties an entity has are documented here: http://lua-api.factorio.com/latest/
If you want to get ahold of me I'm almost always on Discord.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Ability to iterate entity properties

Post by aubergine18 »

More specifically, all of the things that are currently documented are available at via that URL.

But not everything is documented.

For example, where is the documentation for flying-text?

The ability to iterate properties of entities on the map would allow us to discover stuff that's not yet documented.

And, for debugging, it would make it much easier to get hold of all the values of an entity so that we can determine why it's not behaving the way we expect it to behave (ie. what properties did we set wrong or forget to set).

If, for example, we wanted to make an entity inspector tool to assist with mod development, currently we'd have to create a big table listing known properties for each entity type, then when an entity is selected we'd have to reference that list to get the values of its known properties. There are issues with this approach:

1. Not all properties are documented (known)
2. Properties change over time, so our table of entity type -> properties will become outdated

If, instead, we could just serpent.dump an entity, the task of creating in-game tools to assist mod development would be more reliable and effective.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

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

Re: Ability to iterate entity properties

Post by Rseding91 »

aubergine18 wrote:More specifically, all of the things that are currently documented are available at via that URL.

But not everything is documented.

For example, where is the documentation for flying-text?

The ability to iterate properties of entities on the map would allow us to discover stuff that's not yet documented.

And, for debugging, it would make it much easier to get hold of all the values of an entity so that we can determine why it's not behaving the way we expect it to behave (ie. what properties did we set wrong or forget to set).

If, for example, we wanted to make an entity inspector tool to assist with mod development, currently we'd have to create a big table listing known properties for each entity type, then when an entity is selected we'd have to reference that list to get the values of its known properties. There are issues with this approach:

1. Not all properties are documented (known)
2. Properties change over time, so our table of entity type -> properties will become outdated

If, instead, we could just serpent.dump an entity, the task of creating in-game tools to assist mod development would be more reliable and effective.
No, all properties for all entities are documented there.

What you're talking about are not entity properties but are entity creation parameters. Entity properties are things you can access off an entity through the API runtime. Entity creation parameters are documented here: http://lua-api.factorio.com/latest/LuaS ... ate_entity
If you want to get ahold of me I'm almost always on Discord.

User avatar
bobingabout
Smart Inserter
Smart Inserter
Posts: 7352
Joined: Fri May 09, 2014 1:01 pm
Contact:

Re: Ability to iterate entity properties

Post by bobingabout »

You already can iterate through all entities that exist on a surface. there was a change to one of the scripts in early 0.13 that allowed you to not specify an area to scan, and if you didn't, would return a table of all entities on the surface. then you can iterate through that with the for in pairs command as usual.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Ability to iterate entity properties

Post by aubergine18 »

bobingabout wrote:You already can iterate through all entities that exist on a surface. there was a change to one of the scripts in early 0.13 that allowed you to not specify an area to scan, and if you didn't, would return a table of all entities on the surface. then you can iterate through that with the for in pairs command as usual.
Yes, but having got a reference to a specific entity, I can't iterate its properties. I have to maintain a separate lookup table that maps entity type to a list of *known* properties for that type, then check each of those properties manually against the entity object. I can't just do `for k,v in pairs(someEntity)` to list all the properties and current values of that specific entity.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12888
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Ability to iterate entity properties

Post by ssilk »

Hm. It would be enough if that meta-information of all the possible properties would be available somehow. So that you could iterate through the metainformation, not the entity.

what aubergine wants:

Code: Select all


for namey_of_property, property in pairs(entity) do
    ....
What I mean, that is also possiblekl:

Code: Select all

for _, name_of_property in pairs(meta_info_for entities) do
    property = entity[name_of_property]
    ...
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Ability to iterate entity properties

Post by aubergine18 »

Yes, even if it was available via LuaEntity.property_list I could do something like:

Code: Select all

local dump = {}
for _,prop in pairs(someEntity.property_list) do
  dump[prop] = someEntity[prop]
end

log( serpent.block( dump ) )
I'd still much prefer:

Code: Select all

log( serpent.block( someEntity ) )
While docs is great, I want to make a tool in game so I can dump any entity on it and get it's props and values dumped to log or console. I don't want to have to maintain my own list of props for every entity type, as over time it will get out of date (any change in props or entitiy types = manual update = pain).
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

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

Re: Ability to iterate entity properties

Post by Rseding91 »

aubergine18 wrote:Yes, even if it was available via LuaEntity.property_list I could do something like:

Code: Select all

local dump = {}
for _,prop in pairs(someEntity.property_list) do
  dump[prop] = someEntity[prop]
end

log( serpent.block( dump ) )
I'd still much prefer:

Code: Select all

log( serpent.block( someEntity ) )
While docs is great, I want to make a tool in game so I can dump any entity on it and get it's props and values dumped to log or console. I don't want to have to maintain my own list of props for every entity type, as over time it will get out of date (any change in props or entitiy types = manual update = pain).
That's almost completely useless. Some properties are only valid during specific phases of an entity and others are "valid" but do nothing for some entities. Other properties are valid on an entity only if a specific value is used on the prototype and so on.

Why do you want such a list? I can't think of any reason other than "because" - which doesn't justify spending any time on it.
If you want to get ahold of me I'm almost always on Discord.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Ability to iterate entity properties

Post by aubergine18 »

Because I want to dump out the current property values for an entity on the map (specifically any that can be read from the created entity that's on the map). I find myself adding lots of debug code to my scripts to console or log specific properties (often having to go to docs site to work out what props might exist) and really wish I could just create a custom-input that triggers an event handler function that dumps the info about the selected entity to console or log.
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

WildBraas
Inserter
Inserter
Posts: 44
Joined: Sat Feb 16, 2019 6:25 am
Contact:

Re: Ability to iterate entity properties

Post by WildBraas »

Now its possible using Factorio mod debug for Visual Code, with breakpoints and code analysis.
ANd in breakpoint stop will be it possible
lua eval.png
lua eval.png (25.83 KiB) Viewed 2510 times

curiosity
Filter Inserter
Filter Inserter
Posts: 325
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Ability to iterate entity properties

Post by curiosity »

WildBraas wrote:
Sun May 15, 2022 7:06 pm
Now its possible using Factorio mod debug for Visual Code, with breakpoints and code analysis.
It's hardcoded into the plugin for each LuaObject type.

WildBraas
Inserter
Inserter
Posts: 44
Joined: Sat Feb 16, 2019 6:25 am
Contact:

Re: Ability to iterate entity properties

Post by WildBraas »

Yes, but dynamically see what inside entity in right line of code still unpossible wo this extension

Post Reply

Return to “Won't implement”