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!
switch
case tGender is "male"
set the cPermission of this stack to false
answer "Sorry, ladies only"
break
case tAge < 18
set the cPermission of this stack to false
answer "Sorry, adults only"
break
end switch
Last edited by SparkOut on Sun Sep 06, 2015 8:49 pm, edited 2 times in total.
I mostly use if-then, except when choosing from a larger number of options. Then I use the "switch variable" form. With appropriate break.
If you do conditionals on a variable as done in above link, be careful and know what you are doing. You can get surprising result. Although they are consistent with the logic of Switch case.
Switch statements are trickiest when you use the case evaluation form without break statements. Beyond that very specific circumstance outlined in the forum discussion Bernd linked to, they're pretty straightforward and very useful for a wide range of circumstances where if-then blocks may be cumbersome or less flexible.
The key here is that you can either evaluate a condition in the switch statement, or within each case statement, but not both.
As SparkOut wrote, in your code you were evaluating the condition with each case statement, so just removing the comparison value from the switch statement addresses the issue you encountered.
Richard Gaskin LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn