Combine attributes in if statement?
Rockenden
27 Jun 2015, 18:48Can you combine a check for attributes in squiffy? I'm having trouble finding the syntax.
Something like the below example.
Something like the below example.
set("hadfood", "1");
set("haddrink", "1");
{if hadfood=1 && haddrink=1:You are not hungry or thirsty.}
Alex
28 Jun 2015, 19:21You could nest them:
{if hadfood=1:{if haddrink=1:You are not hungry or thirsty.}}
Rockenden
29 Jun 2015, 07:49Thanks, Alex.
theomstea
13 Aug 2015, 18:43Hello,
What if I need to use the "else" part?
You'd have to replicate text:
The workaround I have found is to compute the result of the "and" operation with JS.
Is that what you would do or does someone have a more elegant solution?
Thanks
What if I need to use the "else" part?
You'd have to replicate text:
{if hadfood=1:
{if haddrink=1:You are not hungry or thirsty.}
{else:You are hungry or thirsty.}
}
{else: You are hungry or thirsty.}
The workaround I have found is to compute the result of the "and" operation with JS.
var b=(get("hadfood")==1)&&get("haddrink")==1))
set("hadfoodanddrink",b);
{if haddrinkanddrink:You are not hungry or thirsty.}
{else:You are hungry or thirsty.}
Is that what you would do or does someone have a more elegant solution?
Thanks
Alex
16 Aug 2015, 13:54Yes JavaScript is the way to go for this - the in-line text processor is only good for rather basic checks.
Kilyle
18 Sept 2015, 11:26You don't have to say the entire statement every time, you know.
Or, for more precise information:
I'm sure there's a shorter version I could come up with if I cared to. Point is, don't repeat more than you need to repeat, unless it makes the code unreadable. Notice even the period's after everything else.
You are {if hadfood=true:{if haddrink=true:not}} hungry or thirsty.
Or, for more precise information:
You are
{if hadfood=true:
{if haddrink=true:not hungry or thirsty}{else:thirsty, but not hungry}
}
{else:
{if haddrink=true:hungry, but not thirsty}{else:hungry and thirsty}
}.
I'm sure there's a shorter version I could come up with if I cared to. Point is, don't repeat more than you need to repeat, unless it makes the code unreadable. Notice even the period's after everything else.