Sliders & Images
Kay C Lan
lan.kc.macmail at gmail.com
Wed Aug 6 07:40:38 EDT 2008
On Wed, Aug 6, 2008 at 5:27 PM, H Baric <hbaric at gmail.com> wrote:
>
> Now Randy, your script here makes perfect sense to me as a beginner! Eric's
> not so, but I want it to, so these two scripts I shall take away and learn
> from!
>
You are doing extremely well to already have your head around switch
statements. There are long timers on this List who still shy away from them.
Whilst I would not deter you from learning from Eric's excellent example,
let me offer one really nice feature you can take advantage of with the
Switch statement; and that is the 'default' option.
switch myColour
case "red"
redHandler
break
case "green"
greenHandler
break
case "blue"
blueHandler
break
--handy feature during development
default
answer "I haven't covered the " & myColour & " situation." titled
"Switch Error"
breakpoint
end switch
In this case if you have an option menu, or a dialog box, or whatever, with
the three colour options and you decided to include all the colours of the
rainbow, if you forget to change your switch statement, you will
automatically be told, best of all if you have script debug mode turned on,
once you press OK to the answer dialog box that popped up to tell you about
the Switch error, the debugger will pop up and stop in the very Switch
statement that is missing the extra options! So easy to then fix :-)
Whilst I can normally remember to get the Switch statements sitting right
there in an option menu, I've really come to like Switch statements and my
scripts are now infested with them so I often forget some of the
ramifications of adding additional options. Default picks it up EVERY time.
My stacks are for me, so it doesn't matter if I leave these statements as
is, especially since I'll probably add a new option 2 months down the track
and completely forget again the ramifications that can have. On the other
hand, when you've gone final, it's easy enough to do a global search for
'default' and remove what would be useless lines of code in a perfect
product ;-)
Keep up the Revolution.
More information about the use-livecode
mailing list