[0.18.42] Modded sliders don't step correctly when their range is equal to 1

Bugs that are actually features.
Post Reply
User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

[0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by Therenas »

When creating a modded slider element like this:

Code: Select all

parent.add{type="slider", minimum_value=1,  maximum_value=2}
It steps in values of 0.05 for some reason. It should step in increments of 1, meaning in this case, go from one end of the slider directly to the other end. When setting the maximal_value to 3, it works as expected, going from 1 to 2 to 3. This happens every time the maximum_value = minimum_value + 1.

Edit: Setting value_step to 1 doesn't change anything (I think it's default 1 anyways?), and neither does setting discrete_slider and discrete_values have any effect. I also realize that a slider to select between 1 and 2 does not make much sense, but I want to use it in a context where the maximum_value could be larger in some cases, but it'll be 2 in some. Having a different UI to choose between 1 and 2 would be silly in that case.

osldgoth
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu Feb 26, 2015 3:52 am
Contact:

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by osldgoth »

I've encountered the sliders small steps in my mod ACT. I get around it by checking how much the slider value has changed as seen on line 795

Code: Select all

(math.abs(global.ACT_slider[player.name][recipe.name].value - event.element.slider_value) >= global.settings[player.name]["sensitivity-value"] / 10)
then the slider value gets 'rounded' to the nearest whole number on line 702

Code: Select all

truncateNumber(global.ACT_slider[player.name][recipe.name].value, 0)
after that the caption and the slider value is updated in the function at line 528. All that only because you can't set a step value.

User avatar
bormand
Fast Inserter
Fast Inserter
Posts: 201
Joined: Fri Jun 05, 2020 9:59 am
Contact:

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by bormand »

Looks like it's something with rounding: maximum_value = 2.0000001 works fine, but maximum_value = 2 does not.

P.S. 2.00000001 is a good workaround until this issue would be fixed.

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by Therenas »

bormand wrote:
Fri Aug 07, 2020 6:09 am
Looks like it's something with rounding: maximum_value = 2.0000001 works fine, but maximum_value = 2 does not.

P.S. 2.00000001 is a good workaround until this issue would be fixed.
That is quite interesting. Thanks a lot for the workaround, I'll be able to release my update with that at least.

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

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by Klonan »

Looks like it is working as intended:

Code: Select all

    if (this->max - this->min <= 1 && this->valueStep == 1) // make small number sliders work by default
      this->valueStep = (this->max - this->min) / 20.0;

Xorimuth
Filter Inserter
Filter Inserter
Posts: 624
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by Xorimuth »

Klonan wrote:
Wed Oct 14, 2020 8:25 am
Looks like it is working as intended:

Code: Select all

    if (this->max - this->min <= 1 && this->valueStep == 1) // make small number sliders work by default
      this->valueStep = (this->max - this->min) / 20.0;
Perhaps you could make it < 1 instead of <= 1 to solve OP's problem?
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

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

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by Klonan »

Xorimuth wrote:
Wed Oct 14, 2020 8:38 am
Klonan wrote:
Wed Oct 14, 2020 8:25 am
Looks like it is working as intended:

Code: Select all

    if (this->max - this->min <= 1 && this->valueStep == 1) // make small number sliders work by default
      this->valueStep = (this->max - this->min) / 20.0;
Perhaps you could make it < 1 instead of <= 1 to solve OP's problem?
No, just set the value step if you want it to behave different.

0->1 sliders are very common

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

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by eradicator »

Klonan wrote:
Wed Oct 14, 2020 12:57 pm
just set the value step
Can you give an example? As far as i can tell - and like op said - value_step has no effect.

Here's three failed attempts:

Code: Select all

/c 
game.player.gui.center.clear()
game.player.gui.center.add{type='frame'}.add{type="slider", minimum_value=1,  maximum_value=2, value_step=1}
game.player.gui.center.add{type='frame'}.add{type="slider", minimum_value=1,  maximum_value=2, value=2, value_step=1}
local s = game.player.gui.center.add{type='frame'}.add{type="slider", minimum_value=1,  maximum_value=2, value=2, value_step=1, discrete_slider = true, discrete_values = true}

s.set_slider_value_step(1)
s.set_slider_discrete_slider(true)
s.set_slider_discrete_values(true)
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
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by Klonan »

eradicator wrote:
Wed Oct 14, 2020 4:44 pm
Klonan wrote:
Wed Oct 14, 2020 12:57 pm
just set the value step
Can you give an example? As far as i can tell - and like op said - value_step has no effect.
Ok, there is a 'bug', an issue

The custom widget thinks it has the value step of 1, while internally it was set to 0.05

When you set it to 1, it goes "Oh, I am already at 1, I can just do nothing"

So you need to set it to like, 0.1, then back to 1

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

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by eradicator »

Klonan wrote:
Wed Oct 14, 2020 4:52 pm
So you need to set it to like, 0.1, then back to 1

Code: Select all

/c 
game.player.gui.center.clear()
game.player.gui.center.add{type='frame'}.add{type="slider", minimum_value=1,  maximum_value=2, value_step = 0.01, value = 1}.set_slider_value_step(1)
While that does indeed work it is ugly and incomprehensible.
Klonan wrote:
Wed Oct 14, 2020 4:52 pm
Ok, there is a 'bug', an issue
Why the quotes? Is there some reason this won't/can't be fixed?
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
bormand
Fast Inserter
Fast Inserter
Posts: 201
Joined: Fri Jun 05, 2020 9:59 am
Contact:

Re: [0.18.42] Modded sliders don't step correctly when their range is equal to 1

Post by bormand »

can't be fixed
The problem is that some mods may depend on old behaviour and expect "small number sliders work by default".

I guess that best fix would be to distinguish between "valueStep is not set" (for mods that expect 0..1 sliders work with 0.05 step) and "valueStep is explicitly set" (for mods that specify proper valueStep manually).

Post Reply

Return to “Not a bug”