Login
Remember
IF Answers
Ask a Question

# How to compare two variables in Squiffy?

0 votes
167 views
asked Apr 19 in Authoring by Natas (17 points)

What would be the best way to compare two variables?

{ if varOne == varTwo: [blah blah]}{else: }

This doesnt seem to work for me in Squiffy. It pulls up an error.

- squiffy

## 1 Answer

+1 vote
answered Apr 20 by Alex (486 points)
selected Apr 21 by Natas
Best answer

You need to use JavaScript for this. You could set a new attribute to true or false to tell you if the two attributes are the same. For example:

    @set a=2
    Try two variables the [same](next, b=2) or [different](next, b=3).

    [next]:
        set("same", get("a") == get("b"));

    a = {a}, b = {b}, same = {same}.

This sets the value of "same" to true or false, depending on whether the values of "a" and "b" are the same.

Live example: http://docs.textadventures.co.uk/squiffy/scratchpad/?gistid=68b9556d84d3ffc127e4&filename=same.squiffy

commented Apr 21 by Natas (17 points)
I wish I could give you a bonus for teaching me the neat (next, b=3) trick as well.
commented Apr 21 by Natas (17 points)
There is a bit of a problem. Why doesnt the code.
{if same=true: Placeholder text}{else: } not works?

## Related questions

- Squiffy: How to force two variables to equal based off another variable?
- How to deal with large numbers in Squiffy?
- How to add a random number generator in Squiffy?
- Squiffy: How to fix if else error?
- Squiffy: Extracting Data From Objects Variables.

...