Page 1 of 1
Multiple custom sliders
Posted: Sat May 18, 2013 8:42 pm
by Terryfic
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
Re: Multiple custom sliders
Posted: Sat May 18, 2013 9:37 pm
by Simon
oooh, oooh, I got this one.....
Mister Newman. Mister Newman...

Simon
Re: Multiple custom sliders
Posted: Mon May 20, 2013 1:33 am
by dunbarx
Simon.
Attack!
Craig
Re: Multiple custom sliders
Posted: Mon May 20, 2013 4:43 am
by Simon
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
Re: Multiple custom sliders
Posted: Mon May 20, 2013 8:36 pm
by Terryfic
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
Re: Multiple custom sliders
Posted: Fri May 24, 2013 5:31 pm
by Terryfic
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
Re: Multiple custom sliders
Posted: Fri May 24, 2013 6:13 pm
by dunbarx
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
Re: Multiple custom sliders
Posted: Fri May 24, 2013 8:48 pm
by Terryfic
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
Re: Multiple custom sliders
Posted: Fri May 24, 2013 10:01 pm
by dunbarx
Bravo.
This sort of thing is invaluable in learning how to code like a pro.
Craig