Ability to iterate entity properties
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Ability to iterate entity properties
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.
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.
Re: Ability to iterate entity properties
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.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Ability to iterate entity properties
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.
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.
Re: Ability to iterate entity properties
No, all properties for all entities are documented there.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.
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.
- bobingabout
- Smart Inserter
- Posts: 7352
- Joined: Fri May 09, 2014 1:01 pm
- Contact:
Re: Ability to iterate entity properties
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.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Ability to iterate entity properties
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.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.
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.
Re: Ability to iterate entity properties
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:
What I mean, that is also possiblekl:
what aubergine wants:
Code: Select all
for namey_of_property, property in pairs(entity) do
....
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...
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Ability to iterate entity properties
Yes, even if it was available via LuaEntity.property_list I could do something like:
I'd still much prefer:
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).
Code: Select all
local dump = {}
for _,prop in pairs(someEntity.property_list) do
dump[prop] = someEntity[prop]
end
log( serpent.block( dump ) )
Code: Select all
log( serpent.block( someEntity ) )
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.
Re: Ability to iterate entity properties
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.aubergine18 wrote:Yes, even if it was available via LuaEntity.property_list I could do something like:
I'd still much prefer:Code: Select all
local dump = {} for _,prop in pairs(someEntity.property_list) do dump[prop] = someEntity[prop] end log( serpent.block( dump ) )
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).Code: Select all
log( serpent.block( someEntity ) )
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.
- aubergine18
- Smart Inserter
- Posts: 1264
- Joined: Fri Jul 22, 2016 8:51 pm
- Contact:
Re: Ability to iterate entity properties
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.
Re: Ability to iterate entity properties
Now its possible using Factorio mod debug for Visual Code, with breakpoints and code analysis.
ANd in breakpoint stop will be it possible
ANd in breakpoint stop will be it possible
Re: Ability to iterate entity properties
Yes, but dynamically see what inside entity in right line of code still unpossible wo this extension