Combine attributes in if statement?

Rockenden
Can you combine a check for attributes in squiffy? I'm having trouble finding the syntax.

Something like the below example.


set("hadfood", "1");
set("haddrink", "1");

{if hadfood=1 && haddrink=1:You are not hungry or thirsty.}



Alex
You could nest them:


{if hadfood=1:{if haddrink=1:You are not hungry or thirsty.}}

Rockenden
Thanks, Alex.

theomstea
Hello,

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
Yes JavaScript is the way to go for this - the in-line text processor is only good for rather basic checks.

Kilyle
You don't have to say the entire statement every time, you know.


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.

This topic is now closed. Topics are closed after 180 days of inactivity.

Support

Forums