Slider value never changes

 Using widget 2.0, I’m trying to create and use some sliders. My sliders appear, as a line with a ball on it that can be moved. I can move them. The listener is called. But <slider>.value never changes from what it was at the time the slider was created, no matter what the user does. Here are some snippets of my program:

[lua]

  controlSlider = widget.newSlider({

      top = screenH*1/3, left = screenW/6, width = screenW*2/3, value = 100*degreeOfControl, 

      listener = updateMap})

function updateMap()  

  readSettings()

  . . .

end

function readSettings()

  degreeOfControl = controlSlider.value/100

  equalize = equalizeSlider.value/100.0

  assist = assistSlider.value/100

  special7 = special7Slider.value/50

end

[/lua]

Additional question: the page http://docs.coronalabs.com/api/library/widget/newSlider.html  says that, in order to conserve memory, a slider must be made from an imageSheet. But nowhere does it say how to actually make use of that image sheet in the creation of the slider. Huh?? So I’m not using one, because I don’t know how. Would that be the issue?

Hi @k3_sparklight,

The value should be obtained by the “event” passed to the slider listener, not the slider itself. Please refer to the example on the page you cited (http://docs.coronalabs.com/api/library/widget/newSlider.html) and incorporate it into your own project.

For custom skinning these, I still need to detail that in the docs. I’ll do so when I can prioritize it over other pressing matters.

Best regards,

Brent

See the following for skinning. Hope this helps : http://forums.coronalabs.com/topic/43443-slider-widget-hitboxes/

Thanks, Brent, I’ll do that. But it still seems that there is a bug, either in the documentation or in Widget.sliderObject itself. Because the page you mention indicates that there is a readable  value property, but that property doesn’t seem to be tell the truth. True?

Hi @k3_sparklight,

Are you sure this isn’t working, and it’s not a scoping issue in your code? I just tested this and it appears to be working as stated (.value can be read). However, this may have been a bug that was fixed in a more recent build. Which version of Corona you using?

Brent

Okay, that works. Now, I notice another problem with my sliders. They aren’t aligning horizontally as I would expect. Here’s my setup code (partially updated as per your last message) showing the coordinates used to create the sliders. Attached is my screenshot from the Corona simulator on the Mac. Notice that the sliders are not horizontally aligned, even though I started them all at left = screenW/6. What could be going on here?

(screenW and screenH are the screen width and height in pixels)
 
[lua]
  controlSlider = widget.newSlider({
      top = screenH*1/3, left = screenW/6, width = screenW*2/3, value = 100*degreeOfControl, 
      listener = updateMap})
  equalizeSlider = widget.newSlider({
      top = screenH*1/2, left = screenW/6, width = screenW*2/3, value = 100*equalize, 
      listener = function(event)
        equalize = event.value / 100
        updateMap()
      end
  })
  assistSlider = widget.newSlider({
      top = screenH*2/3, left = screenW/6, width = screenW*2/3, value = 100*assist, 
      listener = updateMap})
  special7Slider = widget.newSlider({
      top = screenH*5/6, left = screenW/6, width = screenW*2/3, value = 50*special7, listener = updateMap})
  
  buildGraph(screenH*1/4, screenH*1/4 - 20)
[/lua]

Hi @k3_sparklight,

What happens if you declare the starting value of all sliders to (say) 50 when you first declare them, then in lines of code afterward, you set them to the values that you need like “100*assist” ?

Hi @k3_sparklight,

The value should be obtained by the “event” passed to the slider listener, not the slider itself. Please refer to the example on the page you cited (http://docs.coronalabs.com/api/library/widget/newSlider.html) and incorporate it into your own project.

For custom skinning these, I still need to detail that in the docs. I’ll do so when I can prioritize it over other pressing matters.

Best regards,

Brent

See the following for skinning. Hope this helps : http://forums.coronalabs.com/topic/43443-slider-widget-hitboxes/

Thanks, Brent, I’ll do that. But it still seems that there is a bug, either in the documentation or in Widget.sliderObject itself. Because the page you mention indicates that there is a readable  value property, but that property doesn’t seem to be tell the truth. True?

Hi @k3_sparklight,

Are you sure this isn’t working, and it’s not a scoping issue in your code? I just tested this and it appears to be working as stated (.value can be read). However, this may have been a bug that was fixed in a more recent build. Which version of Corona you using?

Brent

Okay, that works. Now, I notice another problem with my sliders. They aren’t aligning horizontally as I would expect. Here’s my setup code (partially updated as per your last message) showing the coordinates used to create the sliders. Attached is my screenshot from the Corona simulator on the Mac. Notice that the sliders are not horizontally aligned, even though I started them all at left = screenW/6. What could be going on here?

(screenW and screenH are the screen width and height in pixels)
 
[lua]
  controlSlider = widget.newSlider({
      top = screenH*1/3, left = screenW/6, width = screenW*2/3, value = 100*degreeOfControl, 
      listener = updateMap})
  equalizeSlider = widget.newSlider({
      top = screenH*1/2, left = screenW/6, width = screenW*2/3, value = 100*equalize, 
      listener = function(event)
        equalize = event.value / 100
        updateMap()
      end
  })
  assistSlider = widget.newSlider({
      top = screenH*2/3, left = screenW/6, width = screenW*2/3, value = 100*assist, 
      listener = updateMap})
  special7Slider = widget.newSlider({
      top = screenH*5/6, left = screenW/6, width = screenW*2/3, value = 50*special7, listener = updateMap})
  
  buildGraph(screenH*1/4, screenH*1/4 - 20)
[/lua]

Hi @k3_sparklight,

What happens if you declare the starting value of all sliders to (say) 50 when you first declare them, then in lines of code afterward, you set them to the values that you need like “100*assist” ?