Page 1 of 1

list of buildings...

Posted: Sun May 28, 2017 9:01 pm
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.

Re: list of buildings...

Posted: Sun May 28, 2017 10:36 pm
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.

Re: list of buildings...

Posted: Mon May 29, 2017 8:04 am
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".

Re: list of buildings...

Posted: Mon May 29, 2017 10:51 am
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

Re: list of buildings...

Posted: Mon May 29, 2017 12:11 pm
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.

Re: list of buildings...

Posted: Tue May 30, 2017 8:13 am
by bobingabout
I see.

so it returns something like:

Code: Select all

{
crafting = true,
crafting-with-fluid = true,
chemistry = false,
...
}
That makes sense. Kinda.

Re: list of buildings...

Posted: Tue May 30, 2017 9:47 am
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.

Re: list of buildings...

Posted: Tue May 30, 2017 10:12 am
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?

Re: list of buildings...

Posted: Tue May 30, 2017 10:51 am
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?

Re: list of buildings...

Posted: Tue May 30, 2017 11:04 am
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.

Re: list of buildings...

Posted: Tue May 30, 2017 11:32 am
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 :)

Re: list of buildings...

Posted: Tue May 30, 2017 11:46 am
by Helfima
this mod already exist viewtopic.php?f=92&t=30465

Re: list of buildings...

Posted: Tue May 30, 2017 11:47 am
by darkfrei
We can have only

Code: Select all

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

Re: list of buildings...

Posted: Tue May 30, 2017 4:48 pm
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.