repeating script across multiple objects
Posted: Sat May 25, 2013 3:54 pm
Hi All
I have the following script for a custom slider that sets its thumb position and displays the value in a label (Qtr). The slider and label are in a group.
on mouseMove
put the long id of graphic "tline" of me into CurrentLine
put the long id of graphic "thumb1" of me into Currentthumb
put the height of currentline into lheight
put item 2 of the loc of Currentthumb into tloc
put the top of currentline into ltop
put lheight-(tloc-ltop) into tunits
if the value of tunits >200 then put 200 into tunits
if the value of tunits <0 then put 0 into tunits
put the value of tunits into field "Qtr" of me
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
There are literally dozens of sliders and, although each slider operates independently, exactly the same code is repeated in every one.
Is there any way to share this script (or even the calculations to get the value for tunits) across all the sliders without having to copy and paste the whole script into each group? I'm thinking along the lines of a calling a subroutine in VB, but I can't seem to find anything similar in Livecode.
Regards
Terry
I have the following script for a custom slider that sets its thumb position and displays the value in a label (Qtr). The slider and label are in a group.
on mouseMove
put the long id of graphic "tline" of me into CurrentLine
put the long id of graphic "thumb1" of me into Currentthumb
put the height of currentline into lheight
put item 2 of the loc of Currentthumb into tloc
put the top of currentline into ltop
put lheight-(tloc-ltop) into tunits
if the value of tunits >200 then put 200 into tunits
if the value of tunits <0 then put 0 into tunits
put the value of tunits into field "Qtr" of me
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
There are literally dozens of sliders and, although each slider operates independently, exactly the same code is repeated in every one.
Is there any way to share this script (or even the calculations to get the value for tunits) across all the sliders without having to copy and paste the whole script into each group? I'm thinking along the lines of a calling a subroutine in VB, but I can't seem to find anything similar in Livecode.
Regards
Terry