Page 1 of 1

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

Posted: Wed Aug 05, 2020 9:13 pm
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.

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

Posted: Thu Aug 06, 2020 1:06 am
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.

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

Posted: Fri Aug 07, 2020 6:09 am
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.

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

Posted: Sat Aug 08, 2020 12:57 pm
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.

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

Posted: Wed Oct 14, 2020 8:25 am
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;

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

Posted: Wed Oct 14, 2020 8:38 am
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?

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

Posted: Wed Oct 14, 2020 12:57 pm
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

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

Posted: Wed Oct 14, 2020 4:44 pm
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)

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

Posted: Wed Oct 14, 2020 4:52 pm
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

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

Posted: Wed Oct 14, 2020 6:08 pm
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?

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

Posted: Wed Oct 14, 2020 8:54 pm
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).