list of buildings...

Place to get help with not working mods / modding interface.
Post Reply
_npo6ka_
Fast Inserter
Fast Inserter
Posts: 102
Joined: Mon Sep 26, 2016 10:29 pm
Contact:

list of buildings...

Post by _npo6ka_ »

I want to write a mod that slightly differently displays the recipe for creating an item. To do this, it is necessary to display information about the building in which this recipe can be made.

In Factorio Api -> LuaEntityPrototype, I found the field "crafting_categories :: the dictionary string → Boolean [R]" which returns a boolean instead of the list crafting_categories.

Can I get a list of "assembling-machine" in which i can execute the required recipe?

Sorry for my english.

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

Re: list of buildings...

Post by Rseding91 »

Read the full description of crafting_categories:

http://lua-api.factorio.com/latest/LuaE ... categories
Factorio Lua docs wrote:crafting_categories :: dictionary string → boolean [Read-only]
The crafting categories this entity supports. Only meaningful when this is a crafting-machine or player entity type.

Note: The value in the dictionary is meaningless and exists just to allow the dictionary type for easy lookup.
The dictionary keys are the categories.
If you want to get ahold of me I'm almost always on Discord.

_npo6ka_
Fast Inserter
Fast Inserter
Posts: 102
Joined: Mon Sep 26, 2016 10:29 pm
Contact:

Re: list of buildings...

Post by _npo6ka_ »

Rseding91 wrote:Read the full description of crafting_categories:
http://lua-api.factorio.com/latest/LuaE ... categories
Factorio Lua docs wrote:crafting_categories :: dictionary string → boolean [Read-only]
The crafting categories this entity supports. Only meaningful when this is a crafting-machine or player entity type.

Note: The value in the dictionary is meaningless and exists just to allow the dictionary type for easy lookup.
The dictionary keys are the categories.
This field always returns a boolean value and not a dictionary key. How to get the key when calling this field?
Apparently I do not understand what it means "dictionary string → boolean".

Pandemoneus
Fast Inserter
Fast Inserter
Posts: 127
Joined: Fri May 08, 2015 2:25 pm
Contact:

Re: list of buildings...

Post by Pandemoneus »

_npo6ka_ wrote:
Rseding91 wrote:Read the full description of crafting_categories:
http://lua-api.factorio.com/latest/LuaE ... categories
Factorio Lua docs wrote:crafting_categories :: dictionary string → boolean [Read-only]
The crafting categories this entity supports. Only meaningful when this is a crafting-machine or player entity type.

Note: The value in the dictionary is meaningless and exists just to allow the dictionary type for easy lookup.
The dictionary keys are the categories.
This field always returns a boolean value and not a dictionary key. How to get the key when calling this field?
Apparently I do not understand what it means "dictionary string → boolean".
It means that when you use .crafting_categories, it will return a map of "dictionary string"s to "boolean"s. So when you iterate over crafting_categories, you will want the keys, not the values.
I.e.

Code: Select all

for k,v in pairs(path_to.crafting_categories) do
  print k --this prints my crafting categories!
end
My RSO+Bob's+Angel's modpack: Farlands (outdated)
Mods (current): Resource Labels
Mods (old): Biter Spires

_npo6ka_
Fast Inserter
Fast Inserter
Posts: 102
Joined: Mon Sep 26, 2016 10:29 pm
Contact:

Re: list of buildings...

Post by _npo6ka_ »

Pandemoneus wrote:
_npo6ka_ wrote:
Rseding91 wrote:Read the full description of crafting_categories:
http://lua-api.factorio.com/latest/LuaE ... categories
Factorio Lua docs wrote:crafting_categories :: dictionary string → boolean [Read-only]
The crafting categories this entity supports. Only meaningful when this is a crafting-machine or player entity type.

Note: The value in the dictionary is meaningless and exists just to allow the dictionary type for easy lookup.
The dictionary keys are the categories.
This field always returns a boolean value and not a dictionary key. How to get the key when calling this field?
Apparently I do not understand what it means "dictionary string → boolean".
It means that when you use .crafting_categories, it will return a map of "dictionary string"s to "boolean"s. So when you iterate over crafting_categories, you will want the keys, not the values.
I.e.

Code: Select all

for k,v in pairs(path_to.crafting_categories) do
  print k --this prints my crafting categories!
end
Thank you so much!
Problem solved.

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

Re: list of buildings...

Post by bobingabout »

I see.

so it returns something like:

Code: Select all

{
crafting = true,
crafting-with-fluid = true,
chemistry = false,
...
}
That makes sense. Kinda.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

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

Re: list of buildings...

Post by Rseding91 »

bobingabout wrote:I see.

so it returns something like:

Code: Select all

{
crafting = true,
crafting-with-fluid = true,
chemistry = false,
...
}
That makes sense. Kinda.
No the values are meaningless. The key existing in the dictionary is what's useful. If it exists, then it supports it.
If you want to get ahold of me I'm almost always on Discord.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: list of buildings...

Post by darkfrei »

Code: Select all

for k, category in pairs(path_to.crafting_categories) do
  If category then 
    Function ()
  End
end
Why we are need to iterate category=false?

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

Re: list of buildings...

Post by Rseding91 »

darkfrei wrote:

Code: Select all

for k, category in pairs(path_to.crafting_categories) do
  If category then 
    Function ()
  End
end
Why we are need to iterate category=false?
What?
If you want to get ahold of me I'm almost always on Discord.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: list of buildings...

Post by darkfrei »

bobingabout wrote:so it returns something like:

Code: Select all

{
crafting = true,
crafting-with-fluid = true,
chemistry = false,
...
}
I mean, why we are need the list with booleans, but not just list of positive elements.

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: list of buildings...

Post by orzelek »

darkfrei wrote:
bobingabout wrote:so it returns something like:

Code: Select all

{
crafting = true,
crafting-with-fluid = true,
chemistry = false,
...
}
I mean, why we are need the list with booleans, but not just list of positive elements.
Because there is no set in lua - and table requires key-value pairs.
I'd be curious why they are not all true but thats developer in me :)

Helfima
Fast Inserter
Fast Inserter
Posts: 199
Joined: Tue Jun 28, 2016 11:40 am
Contact:

Re: list of buildings...

Post by Helfima »

this mod already exist viewtopic.php?f=92&t=30465

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: list of buildings...

Post by darkfrei »

We can have only

Code: Select all

{
"crafting",
"crafting-with-fluid",
-- "chemistry", -- it was false
...
}

Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: list of buildings...

Post by Nexela »

darkfrei wrote:We can have only

Code: Select all

{
"crafting",
"crafting-with-fluid",
-- "chemistry", -- it was false
...
}
There are no false values, only a list of true values. It is done this way so you don't have to iterate the whole table to see if the machine supports it.

Post Reply

Return to “Modding help”