How do I set a range for a slider?

https://docs.coronalabs.com/api/library/widget/newSlider.html

I have a basic slider linked to a object.xScale and object.yScale. When I move the slider the object scales but how do I set a range for the scale (or a limit). Meaning I just want the object to scale from 1 - 7, so the slider would start at 1 and max out at 7.

Sliders only have one range: 0…100

You’ll have to interpolate the current slider position to your values.

For your range 1…7 you would use this math to get an interpolated value from the slider range:

Value == valMin + (valMax - valMin) * sliderValue/100

valMin == 1
valMax == 7

Examples

  • sliderValue 0 ==> 1 + (7-1) * 0/100 == 1 + 6 * 0 == 1
  • sliderValue 100 ==> 1 + (7-1) * 100/100 == 1 + 6 * 1 == 7
  • sliderValue 50 ==> 1 + (7-1) * 50/100 == 1 + 6 * 0.5 == 1 + 3 == 4
  • … and so on
2 Likes

@roaminggamer worked great thanks!