Terrible documentation

Place to get help with not working mods / modding interface.
User avatar
luc
Fast Inserter
Fast Inserter
Posts: 244
Joined: Sun Jul 17, 2016 9:53 pm
Contact:

Terrible documentation

Post by luc »

1. lua-api.factorio.com is not searchable. I solved this by downloading the site (wget -m http://lua-api.factorio.com/latest/) and searching with grep. Not ideal as the lines are often huge and fill the whole terminal... but it works.

2. game.findentities() is used in the main modding tutorial on the wiki, but it is not even documented. On the wiki there are no hits (other than the tutorial) and in the Lua reference there are no hits at all.

3. Entities of type "tree" are not in the lua reference either. They appear to be non-blueprintable... but who can say?

4. That I can create an entity of type "tree" but not find it in the Lua reference, also means that there exists no list of possible types. We just have to infer this from what the base mod uses?

5. I cannot find assembling-machine info in the Lua reference. I'd like to know what fields and methods it has (defines.html tells me I must be able to access its inventory because defines.inventory.assembling_machine_input exists.... but how?) and whether it has any events (particularly: recipe changed, or finished crafting an item).

How do people even manage to make mods and write tutorials when functions are not written down anywhere, am I missing something?
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Terrible documentation

Post by Nexela »

luc wrote:1. lua-api.factorio.com is not searchable. I solved this by downloading the site (wget -m http://lua-api.factorio.com/latest/) and searching with grep. Not ideal as the lines are often huge and fill the whole terminal... but it works.
Factorio releases also come with the full api in the documents directory. If you use ATOM as your editor I can send you the factorio api autocomlete package I use.
luc wrote:2. game.findentities() is used in the main modding tutorial on the wiki, but it is not even documented. On the wiki there are no hits (other than the tutorial) and in the Lua reference there are no hits at all.
The modding wiki is way outdated. game.findentities has been replaced with surface.find_entities{}
luc wrote:3. Entities of type "tree" are not in the lua reference either. They appear to be non-blueprintable... but who can say?
Entity prototype definitions are found in the data/base/prototypes folder. Not all entities are blueprintable
luc wrote:4. That I can create an entity of type "tree" but not find it in the Lua reference, also means that there exists no list of possible types. We just have to infer this from what the base mod uses?
Yes, see above. the lua-api is just that, an API for getting/setting stuff via lua. It is not for creating new prototypes
luc wrote:5. I cannot find assembling-machine info in the Lua reference. I'd like to know what fields and methods it has (defines.html tells me I must be able to access its inventory because defines.inventory.assembling_machine_input exists.... but how?) and whether it has any events (particularly: recipe changed, or finished crafting an item).
Information on prototypes is found in the data/base/prototypes folder. All events are found here http://lua-api.factorio.com/latest/events.html. There is no event for recipe change or finished crafting.
luc wrote:How do people even manage to make mods and write tutorials when functions are not written down anywhere, am I missing something?
All of the functions for accessing/changing stuff during run-time is found in the factorio-API. All of the prototype definitions are found in data/base/prototypes
User avatar
luc
Fast Inserter
Fast Inserter
Posts: 244
Joined: Sun Jul 17, 2016 9:53 pm
Contact:

Re: Terrible documentation

Post by luc »

Thank you very much for the thorough response! It is much appreciated :)
Nexela wrote:Factorio releases also come with the full api in the documents directory. If you use ATOM as your editor I can send you the factorio api autocomlete package I use.
Ah, I didn't notice that before.
Nexela wrote:The modding wiki is way outdated. game.findentities has been replaced with surface.find_entities{}
Ah yes, that one I can find in the reference.
Nexela wrote:Entity prototype definitions are found in the data/base/prototypes folder. Not all entities are blueprintable
How can I figure out which ones are blueprintable? Is it possible to make one blueprintable if it isn't?
Nexela wrote:Information on prototypes is found in the data/base/prototypes folder. All events are found here http://lua-api.factorio.com/latest/events.html. There is no event for recipe change or finished crafting.
Alright so I have a custom factory-like building which makes products without needing any inputs (think of it like a cheat, but it draws a massive amount of power to compensate). It seemed easiest to me to make a variant of an assembly machine and let it fill its own inventory using Lua. Upon (1)setting/changing a recipe and (2)completion of an product, it needs to re-fill itself. What is an efficient way to do this?

I was thinking, maybe keep a global array of all these special factories, like global.specialfactories. Then on_built_entity I could check whether it (created_entity) was a special factory and, if yes, add it to global.specialfactories. Then on each tick: foreach (global.specialfactories as factory){ if factory.is_crafting(): continue; else get the recipe and fill inputs }. Does that make sense, or is there a better way?
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Terrible documentation

Post by Nexela »

luc wrote:I was thinking, maybe keep a global array of all these special factories, like global.specialfactories. Then on_built_entity I could check whether it (created_entity) was a special factory and, if yes, add it to global.specialfactories. Then on each tick: foreach (global.specialfactories as factory){ if factory.is_crafting(): continue; else get the recipe and fill inputs }. Does that make sense, or is there a better way?
That sounds about right.
luc wrote:How can I figure out which ones are blueprintable? Is it possible to make one blueprintable if it isn't?
Entities with the not-in-blueprint flag (something like this), entities without forces (trees, simple-entity). There are a couple of other cases too
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2905
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Terrible documentation

Post by darkfrei »

Alright so I have a custom factory-like building which makes products without needing any inputs (think of it like a cheat, but it draws a massive amount of power to compensate).
Mod with water well as assembler with locked recipe and without raw material.
Post Reply

Return to “Modding help”