Page 1 of 1
[0.17.43] auto barreling ignores: auto_barrel = false
Posted: Fri May 24, 2019 3:16 pm
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
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Fri May 24, 2019 4:11 pm
by eradicator
I like double brackets
Code: Select all
if (fluid.auto_barrel ~= false) and ((fluid.icon and fluid.icon_size) or fluid.icons) then
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Fri May 24, 2019 4:19 pm
by AmatorPhasma
eradicator wrote: ↑Fri May 24, 2019 4:11 pm
I like double brackets
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
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Fri May 24, 2019 4:21 pm
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
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Fri May 24, 2019 5:06 pm
by Klonan
Thanks for the report,
This is fixed for the next release
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Fri May 24, 2019 5:14 pm
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?
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Fri May 24, 2019 5:17 pm
by AmatorPhasma
Klonan wrote: ↑Fri May 24, 2019 5:06 pm
Thanks for the report,
This is fixed for the next release
Thanks!
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 11:47 am
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
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 1:43 pm
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
.
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)
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 1:57 pm
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
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 2:12 pm
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.
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 2:42 pm
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
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 3:04 pm
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.
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 3:14 pm
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')
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 3:34 pm
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.
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 3:42 pm
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.
Re: [0.17.43] auto barreling ignores: auto_barrel = false
Posted: Sat May 25, 2019 3:43 pm
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