Groups keyboard shortcuts have been updated
Dismiss
See shortcuts
Skip to first unread message

Jeremy Child

unread,
Jan 1, 2018, 5:51:00 AM1/1/18
to MIT App Inventor Forum
I've been seeing some strange behaviour when setting a slider control's thumb position in the code.

I created a small test app to make sure it wasn't something I'd missed in the code, and the behaviour is still there.  On occasions, the slider "set thumbposition" method sets the slider thumbposition to a value lower than the one you specify.  Experimentation has shown that
1) the under setting is equal to 1% of the slider range.
2) setting it to the same number twice works the second time
3) The behaviour is identical in the companion and in the built app.
4) The behaviour is identical on two separate devices

In the attached app, 
"set to 100" sets to 95.81, then to 100
"set to 200" sets to 195.61, then to 200
"add 10" to 100 adds 5.79 first time, and 10 thereafter
"add 10" to 95.81 adds 10!
"take 10" takes off 15 (ish) each time

Any thoughts?

Jeremy
SliderTest.aia

TimAI2

unread,
Jan 1, 2018, 6:11:23 AM1/1/18
to MIT App Inventor Forum
This might help, the slider can be a bit buggy

Jeremy Child

unread,
Jan 1, 2018, 7:04:49 PM1/1/18
to MIT App Inventor Forum
Thanks, although I think the previous problem related to him not realising that setting the thumbposition programmatically would also trigger a slider.positionchanged event.

I solved my issue by calculating the value I wanted it set to, and then setting the thumbposition to it twice.  In other words:
Instead of "slider.thumbposition = slider.thumbposition + 10"
I had:
"variable = slider.thumbposition + 10
set slider.thumbposition to variable
set slider.thumbposition to variable"

For some reason setting it twice eliminates the odd results I was experiencing previously.

Cheers

Jeremy

Boban Stojmenovic

unread,
Jan 2, 2018, 10:53:40 AM1/2/18
to mitappinv...@googlegroups.com

It's not so bugy if you know what's going on in the back ground as we have a value which is programmatically set to 100 points/steps.

meaning


ex.
min value -> max value
0 -> 100 each step has a value of 1 (100/100) = 1
0 -> 200 each step has a value of 2 (200/100) = 2
0 -> 255 each step has a value of 2.55 (255/100) = 2.55
0 -> 500 each step has a value of 5 (500/100) = 5

In your case when you have value 1-> 500 will be a little different as you already occupy 1 point/step, see the attachment..

as you get the wrong value when you try to go programmatically to 100, as I mentioned 100 "points/steps"
to position it so close to 100 it needs 20 "points/steps" 500/100 = 20
you already occupy 1 point/step and now it will be only 19 left, 499/100=4,99-> 19*4,99=94,81 plus the one we already occupied 94,81+1= 95,81


For my rgb app (youtube) I have manipulated the programmatic value from 100 to 255 so it gives me one step at a time..

/Boban

SliderTest_copy.aia

Boban Stojmenovic

unread,
Jan 2, 2018, 12:49:47 PM1/2/18
to MIT App Inventor Forum
Jeremy responded privately.

Hmm that makes a _lot_ of sense. Thanks.


/Boban
Reply all
Reply to author
Forward
0 new messages