[0.17.43] auto barreling ignores: auto_barrel = false

This subforum contains all the issues which we already resolved.
User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

[0.17.43] auto barreling ignores: auto_barrel = false

Post by AmatorPhasma »

Hi,

After update to 0.17.43 the auto barreling ignores the property auto_barrel = false IF my fluid has icons instead of icon

I think line 320 in data-updates.lua is a bit wrong:

Code: Select all

if (fluid.auto_barrel == nil or fluid.auto_barrel) and (fluid.icon and fluid.icon_size) or fluid.icons then

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by eradicator »

I like double brackets :mrgreen:

Code: Select all

if (fluid.auto_barrel ~= false) and ((fluid.icon and fluid.icon_size) or fluid.icons) then
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by AmatorPhasma »

eradicator wrote:
Fri May 24, 2019 4:11 pm
I like double brackets :mrgreen:

Code: Select all

if (fluid.auto_barrel ~= false) and ((fluid.icon and fluid.icon_size) or fluid.icons) then
Not like this?

Code: Select all

local function check_for_icon_size_in_icons()
..stuff...
end

if (fluid.auto_barrel == nil or fluid.auto_barrel) and (fluid.icon or fluid.icons) and (fluid.icon_size or check_for_icon_size_in_icons) then
Last edited by AmatorPhasma on Fri May 24, 2019 4:37 pm, edited 1 time in total.

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

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by bobingabout »

I think it is missing the double brackets.

Code: Select all

if (fluid.auto_barrel == nil or fluid.auto_barrel) and ((fluid.icon and fluid.icon_size) or fluid.icons) then
The first set of brackets check for the flag being missing, or the flag being set to true., the second set's first set checks for icon and icon_size, and the second set as a whole checks that the fluid has an icon.

to be fair, since the game refuses to let a fluid exist that fails any check in the second brackets, it could be reduced to simply...

Code: Select all

if fluid.auto_barrel == nil or fluid.auto_barrel
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5246
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by Klonan »

Thanks for the report,

This is fixed for the next release

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by eradicator »

@AmatorPhasma:
Well, depends on what the underlying functions assume about icons. User input verification is difficult :D.
bobingabout wrote:
Fri May 24, 2019 4:21 pm
to be fair, since the game refuses to let a fluid exist that fails any check in the second brackets, it could be reduced to simply...

Code: Select all

if fluid.auto_barrel == nil or fluid.auto_barrel
If i had to take a bet, i'd say they check for icons so that the generator function doesn't cause errors itself.
Hm i still wonder why it's using "x==nil or value" instead of "x~=false". Are there any unintuitive performance implications hidden in that?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
AmatorPhasma
Fast Inserter
Fast Inserter
Posts: 126
Joined: Sat Aug 05, 2017 8:20 pm
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by AmatorPhasma »

Klonan wrote:
Fri May 24, 2019 5:06 pm
Thanks for the report,

This is fixed for the next release
Thanks! :mrgreen:

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5246
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by Klonan »

eradicator wrote:
Fri May 24, 2019 5:14 pm
Hm i still wonder why it's using "x==nil or value" instead of "x~=false". Are there any unintuitive performance implications hidden in that?
Now it uses "if auto_barrel == false then return end", in a specific "process 1 fluid" function

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

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by bobingabout »

eradicator wrote:
Fri May 24, 2019 5:14 pm
@AmatorPhasma:
Well, depends on what the underlying functions assume about icons. User input verification is difficult :D.
bobingabout wrote:
Fri May 24, 2019 4:21 pm
to be fair, since the game refuses to let a fluid exist that fails any check in the second brackets, it could be reduced to simply...

Code: Select all

if fluid.auto_barrel == nil or fluid.auto_barrel
If i had to take a bet, i'd say they check for icons so that the generator function doesn't cause errors itself.
Hm i still wonder why it's using "x==nil or value" instead of "x~=false". Are there any unintuitive performance implications hidden in that?
not false would work, because nil isn't false. (in fact I've used that before too) but the original code was a specific check for nil (not defined) or just the value (which is true for pretty much everything other than nil, false or 0)
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5246
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by Klonan »

bobingabout wrote:
Sat May 25, 2019 1:43 pm
(which is true for pretty much everything other than nil, false or 0)
0 is true in Lua

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

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by bobingabout »

Klonan wrote:
Sat May 25, 2019 1:57 pm
bobingabout wrote:
Sat May 25, 2019 1:43 pm
(which is true for pretty much everything other than nil, false or 0)
0 is true in Lua
Then it's a stupid bollocks language. 0 is false in MOST languages.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by eradicator »

My original question was more like "is x~= false slower in that case?". Because i noticed that "if a then" is unexpectedly faster than "if a ~= nil then". (I know they mean slightly different things). But thanks for the answers :).
bobingabout wrote:
Sat May 25, 2019 2:12 pm
Klonan wrote:
Sat May 25, 2019 1:57 pm
bobingabout wrote:
Sat May 25, 2019 1:43 pm
(which is true for pretty much everything other than nil, false or 0)
0 is true in Lua
Then it's a stupid bollocks language. 0 is false in MOST languages.
Luckily(?) i'm not experienced enough to have strong feelings about conventions like this.
What gets me again and again is the fake/pseudo ternary operation in lua though:

Code: Select all

a = nil
b = false
c = 0
x = a and b or c
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by bobingabout »

eradicator wrote:
Sat May 25, 2019 2:42 pm
What gets me again and again is the fake/pseudo ternary operation in lua though:

Code: Select all

a = nil
b = false
c = 0
x = a and b or c
I actually like that part, when I understand it.
First the order of operations, And before Or.

so you have a and b. a returns false, and b is false, so, either way it's false.
false or c, C is 0, which Klonan said is true, so... false or c returns 0, because false or true is true, so the true value gets passed.
therefore x = 0.

Also, in these cases, the first (left to right, or Boolean breakdown) true value is always used first too.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by eradicator »

bobingabout wrote:
Sat May 25, 2019 3:04 pm
Also, in these cases, the first (left to right, or Boolean breakdown) true value is always used first too.
It's actually "the last evaluated value" as far as i can tell. The pseudo-trinary mainly breaks cases where i want "give me the first non-nil value". But i'll give you another example that might work better for you:

Code: Select all

x = false and false or nil
y = nil or false and false
Edit: evaluation is more visible when it does something:

Code: Select all

x = false and false or print('evaluated')
y = nil or false and print('evaluated')
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by bobingabout »

eradicator wrote:
Sat May 25, 2019 3:14 pm
bobingabout wrote:
Sat May 25, 2019 3:04 pm
Also, in these cases, the first (left to right, or Boolean breakdown) true value is always used first too.
It's actually "the last evaluated value" as far as i can tell. The pseudo-trinary mainly breaks cases where i want "give me the first non-nil value". But i'll give you another example that might work better for you:

Code: Select all

x = false and false or nil
y = nil or false and false
Edit: evaluation is more visible when it does something:

Code: Select all

x = false and false or print('evaluated')
y = nil or false and print('evaluated')
I never really understood how it works differently between false and nil, but in the example of the fix for locale...

Code: Select all

    localised_name = {"item-name.filled-barrel", fluid.localised_name or {"fluid-name." .. fluid.name}},
if fluid.localised_name has a value, that's what is used, if it doesn't (it's nil) then {"fluid-name." .. fluid.name} is used. For at least the case of an 'or' where a Boolean state is concerned, the FIRST true is used.
And that part of it specifically, is something I like about Lua, because you don't have to create if blocks all over the place to check states, you can literally just put 'a or b' in a table, and it'll use the appropriate entry.
Creator of Bob's mods. Expanding your gameplay since version 0.9.8.
I also have a Patreon.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5207
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by eradicator »

bobingabout wrote:
Sat May 25, 2019 3:34 pm
For at least the case of an 'or' where a Boolean state is concerned, the FIRST true is used.
That's because logical "or" is true if *one* of the values is true. Therefor if the first value is true, the second value becomes irrelevant for the truth value of the "or" expression and is not evaluated. Therefor for "true or x" the first value is also the last *evaluated* value. For "and" on the contrary if the first value is "false" then the expression must also be false and the second value is not evaluated. That's what the edited example with the print() was supposed to demonstrate :).

Btw, concerting "true or not" lua is actually quite easy. Literal <nil> is the only value that is considered "false", every other value is true. And the only excption to that rule is literal <false>.
Other languages have far more exceptions, for example in python most *empty* tables are also false.
Last edited by eradicator on Sat May 25, 2019 3:45 pm, edited 2 times in total.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

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

Re: [0.17.43] auto barreling ignores: auto_barrel = false

Post by darkfrei »

The property must be fluid.disable_barreling, then nil or false will be the same.

Code: Select all

if  (not fluid.disable_barreling) and (fluid.icon or fluid.icons) and (fluid.icon_size or icon_size_inside (fluid.icons)) then

Post Reply

Return to “Resolved Problems and Bugs”