Page 1 of 1

Ability to iterate entity properties

Posted: Fri Oct 07, 2016 2:27 am
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.

Re: Ability to iterate entity properties

Posted: Fri Oct 07, 2016 5:46 am
by Rseding91
All of the properties an entity has are documented here: http://lua-api.factorio.com/latest/

Re: Ability to iterate entity properties

Posted: Fri Oct 07, 2016 2:27 pm
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.

Re: Ability to iterate entity properties

Posted: Fri Oct 07, 2016 2:36 pm
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

Re: Ability to iterate entity properties

Posted: Fri Oct 07, 2016 3:01 pm
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.

Re: Ability to iterate entity properties

Posted: Fri Oct 07, 2016 3:36 pm
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.

Re: Ability to iterate entity properties

Posted: Sat Oct 08, 2016 12:24 am
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]
    ...

Re: Ability to iterate entity properties

Posted: Sat Oct 08, 2016 12:56 am
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).

Re: Ability to iterate entity properties

Posted: Sat Oct 08, 2016 1:14 am
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.

Re: Ability to iterate entity properties

Posted: Sat Oct 08, 2016 1:19 am
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.

Re: Ability to iterate entity properties

Posted: Sun May 15, 2022 7:06 pm
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 2609 times

Re: Ability to iterate entity properties

Posted: Sun May 15, 2022 7:57 pm
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.

Re: Ability to iterate entity properties

Posted: Sun May 15, 2022 8:05 pm
by WildBraas
Yes, but dynamically see what inside entity in right line of code still unpossible wo this extension