Using 'If' in Squiffy

OddyOdding
01 Apr 2020, 10:00

if (squiffy.story.seen("Wallet")) alert ("Hey Daniella, what's your phone's password?");{else:"Hey, former boss, what's the password for your phone?"}

Above is the code I use, I'm pretty sure there's something wrong there, but I'm not sure what exactly.


Bluevoss
02 Apr 2020, 14:52

Number of issues. Confusion of semi-colons. Also, you can't just put dialog in JS script.

Here's code where I make them both alerts. If you don't want them alerts, you'll have to use a set command to get the script into your squiffy flow.

[[init]]:

[[Wallet]]

[[test]]

[[Wallet]]:

This is the wallet code.

[[test]]

[[test]]:

    if (squiffy.story.seen("Wallet"))
        { alert ("Hey Daniella, what's your phone's password?");}
    else
        { alert ("Hey, former boss, what's the password for your phone?");}

Bluevoss
02 Apr 2020, 14:52

BTW, I like that squiffy.story.seen trick. Didn't know you could do that.


mrangel
02 Apr 2020, 16:33

If you're using the alert function in both cases, you could alternatively use the ternary operator ?: instead of if.

    alert (squiffy.story.seen("Wallet")
      ? "Hey Daniella, what's your phone's password?"
      : "Hey, former boss, what's the password for your phone?");

OddyOdding
03 Apr 2020, 12:29

No, both of those code doesn't seem working, by the way is there a way to change the text instead of using the alert?


Bluevoss
03 Apr 2020, 13:04

I think you'd need to say something like:

    if (squiffy.story.seen("Wallet"))
        { set("outStr","Hey Daniella, what's your phone's password?");}
    else
        { set("outStr","Hey, former boss, what's the password for your phone?");}

...and then use {outStr} inside your squiffy code to print out what you needed.


OddyOdding
07 Apr 2020, 12:05

Which one should you check?

Wallet

Money

Phone

The 'mobile makeup kit'

Or perhaps you should do something else?

You decided to keep the money on the purse, for 'safe keeping'

Phone:⁵ You checked the phone first. Its an Iphone 11 Pro Max, the one with the 3 lens that look like a beard shaver.

Turning it on, you see that it has a number password. You turned your head towards your boss and said

if (squiffy.story.seen("Wallet")) null else null

I tried the code, it doesnt work well.


Bluevoss
07 Apr 2020, 12:31

You can't use JS code in the middle of squiffy code, only at the top. To use it in the middle, try this...

{if seen Wallet: Hey Daniella, what's your phone's password?}
{else: Hey, former boss, what's the password for your phone?}

This is the pure squiffy solution. Let me know if it works.


OddyOdding
08 Apr 2020, 10:32

Thank you Bluevoss, It works perfectly