Page 1 of 1

[1.1] How to know if an object is stackable?

Posted: Wed Dec 15, 2021 2:56 pm
by yaim904
What do I want?
I want a way to identify the objects that cannot be stacked.
Context
I am creating some code to alter the size of the stacks in the objects, however I can't find a way to identify the objects that are stackable from those that are not.

According to the documentation, there is a flag with this objective, but as you can see in this code that is not always present

Code: Select all

[ 'light-armor' ] = {
    [ 'type' ] = 'armor'
    [ 'name' ] = 'light-armor'
    [ 'icon' ] = '__base__/graphics/icons/light-armor.png'
    [ 'icon_size' ] = 64
    [ 'icon_mipmaps' ] = 4
    [ 'resistances' ] = { ... }
    [ 'subgroup' ] = 'armor'
    [ 'order' ] = 'a[light-armor]'
    [ 'stack_size' ] = 1
    [ 'infinite' ] = true
}
This information I got from data.raw. One of these objects is applicable and the other is not, how to differentiate them?

Code: Select all

[ 'nuclear-fuel' ] = {
    [ 'type' ] = 'item'
    [ 'name' ] = 'nuclear-fuel'
    [ 'icon' ] = '__base__/graphics/icons/nuclear-fuel.png'
    [ 'icon_size' ] = 64
    [ 'icon_mipmaps' ] = 4
    [ 'pictures' ] = { ... }
    [ 'fuel_category' ] = 'chemical'
    [ 'fuel_value' ] = '1.21GJ'
    [ 'fuel_acceleration_multiplier' ] = 2.5
    [ 'fuel_top_speed_multiplier' ] = 1.15
    [ 'subgroup' ] = 'processed-fuel'
    [ 'order' ] = 'q[uranium-rocket-fuel]'
    [ 'stack_size' ] = 1
}

Re: [1.1] How to know if an object is stackable?

Posted: Wed Dec 15, 2021 3:58 pm
by Stringweasel
That's because `light-armor` is of type `armor`, not `item`. When you have something in some inventory, they will always be of type `item`, and have a defined stack size. Just like the `nuclear-fuel` item you've shown. There will be a seperate entry for `light-armor` of type `item`, which will have the stacksize property.

https://wiki.factorio.com/Prototype/Item#stack_size

Re: [1.1] How to know if an object is stackable?

Posted: Wed Dec 15, 2021 4:25 pm
by yaim904
Stringweasel wrote:
Wed Dec 15, 2021 3:58 pm
As I understand it, I cannot modify the armor because it is not of the Item type, but that would mean that I cannot modify the Module type.

Code: Select all

[ 'speed-module' ] = {
    [ 'type' ] = 'module'
    [ 'name' ] = 'speed-module'
    [ 'localised_description' ] = { ..  }
    [ 'icon' ] = '__space-exploration-graphics__/graphics/icons/modules/speed-1.png'
    [ 'icon_size' ] = 64
    [ 'icon_mipmaps' ] = 1
    [ 'subgroup' ] = 'module-speed'
    [ 'category' ] = 'speed'
    [ 'tier' ] = 1
    [ 'order' ] = 'a[speed]-a[speed-module-1]'
    [ 'stack_size' ] = 50
    [ 'effect' ] = { ... }
    [ 'beacon_tint' ] = { ... }
    [ 'art_style' ] = 'vanilla'
    [ 'requires_beacon_alt_mode' ] = false
}
But it is something that my code does without problem, so I can conclude that it is not the reason or answer I am looking for.

Re: [1.1] How to know if an object is stackable?

Posted: Wed Dec 15, 2021 6:39 pm
by Silari
The flag is only used for items which should not ever be stacked in any circumstance - mostly things like blueprints/planners. Other things, even with a stack size of 1, can be stacked in some circumstances. Most notably in machine inputs so they can be used in a recipe that requires more than 1 of the item. Items with an equipment grid can never be stacked. Possibly also true for items with in inventory, don't know as those aren't used much.

Essentially, if the item doesn't have that flag, and doesn't have an equipment grid, it is possible to stack it.
Stringweasel wrote:
Wed Dec 15, 2021 3:58 pm
That's because `light-armor` is of type `armor`, not `item`. When you have something in some inventory, they will always be of type `item`, and have a defined stack size. Just like the `nuclear-fuel` item you've shown. There will be a seperate entry for `light-armor` of type `item`, which will have the stacksize property.

https://wiki.factorio.com/Prototype/Item#stack_size
The armor type is an extension of the tool type, which is an extension of item. It has all the same properties any item does.

Re: [1.1] How to know if an object is stackable?

Posted: Wed Dec 15, 2021 8:44 pm
by yaim904
So ... there is no way to know if they are not stackable??

Is there a way or can items be created in control.lua ??

Re: [1.1] How to know if an object is stackable?

Posted: Wed Dec 15, 2021 11:49 pm
by Silari
If by stackable, you mean can not be stacked under any circumstances, then yes. Check for the "not-stackable" flag, if the item has an equipment_grid, or if it has an inventory - if any of those are true then it's not stackable.

Otherwise, if stack-size is 1 then it won't stack in a players inventory/chest/wagon/most circumstances, but might in an assembler if a recipe uses it.

Re: [1.1] How to know if an object is stackable?

Posted: Thu Dec 16, 2021 10:11 am
by yaim904
Silari wrote:
Wed Dec 15, 2021 11:49 pm
I understand, thanks for the help.

Re: [1.1] How to know if an object is stackable?

Posted: Tue Oct 18, 2022 9:51 am
by Pi-C
Silari wrote:
Wed Dec 15, 2021 11:49 pm
If by stackable, you mean can not be stacked under any circumstances, then yes. Check for the "not-stackable" flag, if the item has an equipment_grid, or if it has an inventory - if any of those are true then it's not stackable.
Sorry for necroing this thread. While updating one of my mods, I noticed that a property

Code: Select all

stackable = false
was used in the definition of a selection-tool. Unfortunately, while we can compare LuaAPI of different Factorio versions, there is no history of the prototype definitions. Do you know whether item.stackable ever was a valid property? It's not really important (I've removed that from my WIP version), I'm just wondering how this ever got included. :-D

Re: [1.1] How to know if an object is stackable?

Posted: Wed Oct 19, 2022 12:58 am
by Silari
Pi-C wrote:
Tue Oct 18, 2022 9:51 am
Unfortunately, while we can compare LuaAPI of different Factorio versions, there is no history of the prototype definitions. Do you know whether item.stackable ever was a valid property? It's not really important (I've removed that from my WIP version), I'm just wondering how this ever got included. :-D
It's a wiki - you've got the history button to go through and examine old versions. It was a property at some point according to the wiki: https://wiki.factorio.com/index.php?tit ... did=176933

Didn't check every one to see when it was added/moved to a flag but it was a property at one point (or the wiki mistakenly said it was a property, which would just as easily explain why you used it)

Re: [1.1] How to know if an object is stackable?

Posted: Fri Nov 04, 2022 6:51 pm
by yaim904
Pi-C wrote:
Tue Oct 18, 2022 9:51 am
Understand

The displayed data is taken from data.raw in lua code
yaim904 wrote:
Wed Dec 15, 2021 2:56 pm

Code: Select all

[ 'light-armor' ] = {
    [ 'type' ] = 'armor'
    [ 'name' ] = 'light-armor'
    [ 'icon' ] = '__base__/graphics/icons/light-armor.png'
    [ 'icon_size' ] = 64
    [ 'icon_mipmaps' ] = 4
    [ 'resistances' ] = { ... }
    [ 'subgroup' ] = 'armor'
    [ 'order' ] = 'a[light-armor]'
    [ 'stack_size' ] = 1
    [ 'infinite' ] = true
}

Code: Select all

[ 'nuclear-fuel' ] = {
    [ 'type' ] = 'item'
    [ 'name' ] = 'nuclear-fuel'
    [ 'icon' ] = '__base__/graphics/icons/nuclear-fuel.png'
    [ 'icon_size' ] = 64
    [ 'icon_mipmaps' ] = 4
    [ 'pictures' ] = { ... }
    [ 'fuel_category' ] = 'chemical'
    [ 'fuel_value' ] = '1.21GJ'
    [ 'fuel_acceleration_multiplier' ] = 2.5
    [ 'fuel_top_speed_multiplier' ] = 1.15
    [ 'subgroup' ] = 'processed-fuel'
    [ 'order' ] = 'q[uranium-rocket-fuel]'
    [ 'stack_size' ] = 1
}
The problem is that there are non-stackable objects but they do not have any indicator, such as armor.

And they are confused with those with the objects that can be stacked.

All I'm looking for is a way to differentiate it.