Multiple custom sliders

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Terryfic
Posts: 19
Joined: Sun May 05, 2013 3:50 pm

Multiple custom sliders

Post by Terryfic » Sat May 18, 2013 8:42 pm

Hi All

I have managed to create a vertical slider (with a lot of help from forum members). The slider is contained in a group and consists of a line (tline) and a thumb(thumb1). I want to copy this group to create several sliders, but I can only get the first one to work correctly. I am using the following code in each group:

Local Currentline, Currentthumb
on mouseMove
put the long id of graphic "tline" of me into CurrentLine
put the long id of graphic "thumb1" of me into Currentthumb
if item 2 of the mouseLoc > 250 then exit mousemove
if item 2 of the mouseLoc < 50 then exit mousemove
if intersect(Currentthumb,Currentline) and the mouse is down then set the loc of Currentthumb to item 1 of the loc of Currentline & "," & item 2 of the mouseLoc
end mouseMove

I assumed that by using the long id (which is presumably unique for each object) and the "of me" statement (which I assume refers to the group) that this would allow the sliders to operate independently, despite the duplicate names for the line and the thumb.

Am I missing something?

Regards

Terry

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Multiple custom sliders

Post by Simon » Sat May 18, 2013 9:37 pm

oooh, oooh, I got this one.....
Mister Newman. Mister Newman...
:)
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Multiple custom sliders

Post by dunbarx » Mon May 20, 2013 1:33 am

Simon.

Attack!

Craig

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Multiple custom sliders

Post by Simon » Mon May 20, 2013 4:43 am

Actually Terry,
Your code works for me. The only difference is the cursor must be inside the group.
Oh, and your code is in the group script right?


Simon
Attachments
cust_slide.zip
LC 6
(986 Bytes) Downloaded 257 times
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Terryfic
Posts: 19
Joined: Sun May 05, 2013 3:50 pm

Re: Multiple custom sliders

Post by Terryfic » Mon May 20, 2013 8:36 pm

Hi Simon

Thanks very much for this. The code was in the group script, so not sure why mine wouldn't work, but I did notice that the group name in one of the groups I was testing was greyed out, so I couldn't enter a group name (I think I might have accidentally grouped more than one slider when using copying and pasting shortcuts).

In a stroke of genius you have also answered what was going to be my next question, which was how to display the slider values in real time. I was having problems getting this to display in a field but your 'Put the Mouseloc' statement gave me a major clue. I have just replaced this with the line:

put item 2 of the loc of Currentthumb into field "Q1Units"

...and it works a treat. Just need to do the math now to calibrate the scale and get it to display low to high as the thumb is dragged upwards.

Told you I was a beginner!

This should keep me busy for a few days but as Mr S said..."I will be back". :)

Regards

Terry

Terryfic
Posts: 19
Joined: Sun May 05, 2013 3:50 pm

Re: Multiple custom sliders

Post by Terryfic » Fri May 24, 2013 5:31 pm

Hi Simon

I wonder if you can help? I created this slider array (file attached), based on the one you uploaded and, last night, it was working fine. I opened it again today and I am immediately getting the following error:

executing at 8:15:53 PM
Type Chunk: error in object expression
Object BSQ 12
Line put item 2 of the loc of Currentthumb into field "Qtr12"
Hint mouseMove

This is happening randomly with all the groups (BSQ 1 to 12) whether I have clicked them or not.

What I don't get is how it can work perfectly one day, but not the next? The only thing I have added to the original script is the line:

put item 2 of the loc of Currentthumb into field.... (followed by the name of the appropriate label field)

Hope you can shed some light.

Regards

Terry
Attachments
Slider Tester.zip
Slider Tester
(2.21 KiB) Downloaded 242 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Multiple custom sliders

Post by dunbarx » Fri May 24, 2013 6:13 pm

Terry.

The object reference "currentThumb" contains no content when you open the stack in a new session. You can address this by changing the script, of course, or perhaps by storing that value in a custom property, which is saved in the stack file.

Custom properties can be considered variables that are stored as part of the stack resources, accessible everywhere, like globals, and even more permanent than globals.

Craig Newman

EDIT:

In fact, all your thumb references are too local for this to work. I cannot believe they ever did. Make this a global, or better, a custom property.

This is the sort of thing that you really need to slog through. The benefits will be enormous. Pay attention to the error. Note that the value of currentThumb is empty whenever the cursor enters a new group. Note also that all your graphics are lableled "thumb1". This could easily cause confusion when trying to reference one of them in particular. Good luck. Write back...

Craig Newman

Terryfic
Posts: 19
Joined: Sun May 05, 2013 3:50 pm

Re: Multiple custom sliders

Post by Terryfic » Fri May 24, 2013 8:48 pm

Hi Craig

Thanks for your advice. Fingers crossed, it seems to be working fine now. I've declared Currentline and Currentthumb as Global variables on the card script and removed the local variable declarations. Fixing the null content issue was as simple as moving the position of the line:

put item 2 of the loc of Currentthumb into field "Qtr" of me

This now appears after the line that refers to its identity.

A bonus is that now I know that it wasn't the groupings that was causing the error, I have included the Qtr field in each slider group and they all work independently using "of me" without the need for separate names. This will save me a shedload of coding on the main project.

Thanks again.

Regards

Terry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Multiple custom sliders

Post by dunbarx » Fri May 24, 2013 10:01 pm

Bravo.

This sort of thing is invaluable in learning how to code like a pro.

Craig

Post Reply