It is currently April 30th, 2024, 8:37 am

Select Case

Get help with creating, editing & fixing problems with skins
CarlPalmer
Posts: 13
Joined: December 22nd, 2012, 6:00 pm

Select Case

Post by CarlPalmer »

Ok, I have 3 states that a variable could be in. 1, 0, -1.

Based on the state I want to set the LeftMouseDownAction of an Image Meter. I am assuming that I want to use ifabovevalue, ifbelowvalue, and ifequalvalue, but I am not sure how to implement it properly.

I have done some searching, but I am not sure.

Can you point me in the right direction?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Select Case

Post by Kaelri »

Something like this would be the usual approach:

Code: Select all

[MeasureCase]
Measure=Calc
Formula=#Var#
DynamicVariables=1
; First, if #Var# = 1:
IfAboveValue=0
IfAboveAction=!SetOption ImageMeterName LeftMouseDownAction "..."
; Second, if #Var# = 0:
IfEqualValue=0
IfEqualAction=!SetOption ImageMeterName LeftMouseDownAction "..."
; Third, if #Var# = -1:
IfBelowValue=0
IfBelowAction=!SetOption ImageMeterName LeftMouseDownAction "..."
Note that these three cases happen to be exactly the maximum that this approach can handle (since "above," "equal" and "below" are the only conditional options). Here's an alternative approach that would allow any number of cases:

Code: Select all

[ImageMeterName]
Meter=Image
DynamicVariables=1
MeterStyle=Style#Var#

    [Style1]
    LeftMouseDownAction=...

    [Style0]
    LeftMouseDownAction=...

    [Style-1]
    LeftMouseDownAction=...
(Also, as a general piece of advice, we usually recommend using LeftMouseUpAction instead of LeftMouseDownAction, since having a "down" trigger interferes with the user's ability to click and drag the skin. You may have different needs for your skin, of course. :)
CarlPalmer
Posts: 13
Joined: December 22nd, 2012, 6:00 pm

Re: Select Case

Post by CarlPalmer »

Oh nice!!! Thank you, that will do the trick nicely.

I definitely concur up is better than down. I was using code from a sample skin I was looking at. Thanks for pointing that out.