Small Basic Forum
How Does Slider Work ? - Printable Version

+- Small Basic Forum (https://litdev.uk/mybb)
+-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1)
+--- Forum: Challenges (https://litdev.uk/mybb/forumdisplay.php?fid=5)
+--- Thread: How Does Slider Work ? (/showthread.php?tid=105)



How Does Slider Work ? - ata - 07-16-2024

Hi everybody Smile  The following does not work properly.Could you please help me understand the slider logic?

Code:
x[1]= Shapes.AddText(1)
Shapes.Zoom(x[1],7,7)
Shapes.Move(x[1],600,120)
For i= 2 To 12
  x[i]= Shapes.AddText(i)
  Shapes.Zoom(x[i],7,7)
  y= Shapes.GetTop(x[i-1])
  Shapes.Move(x[i],600,y+105)
  y= Shapes.GetTop(x[i])
EndFor

LDControls.SliderMaximum= 2
Slider= LDControls.AddSlider(40,600,"V")
Shapes.Move(slider,500,100)
t= LDControls.SliderGetValue(slider)
Stack.PushValue("t",t)
LDControls.SliderChanged= change

Sub change
  t= Stack.PopValue("t")
  z= LDControls.SliderGetValue(slider) 
    If z>t Or z=t Then
      For i= 1 To 12
        Shapes.Move(x[i],600,Shapes.GetTop(x[i])-2)
      EndFor
      v= LDControls.SliderGetValue(Slider)
      Stack.PushValue("t",v)
    ElseIf z<t then
      For i= 1 To 12
        Shapes.Move(x[i],600,Shapes.GetTop(x[i])+2)
      EndFor
      v= LDControls.SliderGetValue(Slider)
      Stack.PushValue("t",v)
  EndIf
EndSub



RE: How Does Slider Work ? - z-s - 07-16-2024

I edited your posts and added mycode so it can be easily copied.
For more info visit: https://litdev.uk/mybb/misc.php?action=help&hid=7
I will study your code.


RE: How Does Slider Work ? - ata - 07-16-2024

Thank you ZS


RE: How Does Slider Work ? - z-s - 07-16-2024

What is error


RE: How Does Slider Work ? - coder - 07-16-2024

The slider movement is not consistent. The numbers do not always stay where they should be. For example; When I drag the number 1 to the last value of the slider, the y axis should always come to the same place. However, sometimes the number 1 goes too high on the y axis and does not appear when I call it back. thank you


RE: How Does Slider Work ? - litdev - 07-16-2024

Hi ata,zs,coder

I'm totally not sure I fully follow what you are describing, but I think it may be the following.

The amount you move the images is always + or - 2 pixels, depending on if the slider is high or lower compared to the last time it was set.

The slider event will only be called 'as the OS detects a change'.  If you move it very fast, then the slider may go up 20% and the images move up 2 pixels.  If you then move the slider slowly down 20% to where you started the slider event may be called several (say 5 times) and the images will move a total of 10 pixels down.

So, depending on the speed you move the slider, the images and slider can get out of sync.

To fix, I first suggest that you write out some debugging data like TextWindow.WriteLine(z) inserted after line 21.

Then, what you want is the absolute position (y coord) of the images to be related to the absolute position (value) of the slider - no need to store old values in the stack.  I leave you to figure this a bit, rather than modifying your code.


RE: How Does Slider Work ? - ata - 07-17-2024

Thank you Litdev