Why is my IF command not working.

TyCamden
In my storybook, to test something, I changed the coffee variable at the beginning to be zero. Then I ran it expecting that if I fell on the sidewalk, the following would activate:

{if coffee<1: [[Finish]](YouLose)}


But it does not seem to do anything at all. Please let me know why not. Thanks !

@start intro

[[intro]]:
@set coffee=0
@set FellOnIceFlag=0
@set Donut=0
@set Late=0

@title The Coffee Cup

A man takes his plastic coffee cup from the cupboard. His favorite one. It is insulated to keep his coffee warmer, longer. It is black, and without design, serious and businesslike. And a handle with a comfortable grip.

He fills his coffee cup. It is pleased.

"Man, do I feel good. But, where am I? What am I? I appear to be a coffee cup. But... I have no memory before this one. Well... what happens now?"

[[The man heads to work]]

[[The man likes sugar in his coffee]]

[[The man decides to drink tea]]

[[The man likes sugar in his coffee]]:

The man likes sugar in his coffee. He opens a pack, and dumps it in.

"What is this powder that is being poured into me? It is so sweet. But... how am I tasting it? Or seeing anything? I don't have facial features. Not even a mouth. So, I cannot he heard or understood. HEY! MAN WITH THE POWDER! Nothing."

[[The man heads to work]]

[[The man likes cream in his coffee]]

[[The man decides to drink tea]]:

The man says aloud, "I'm tired of coffee today. I think I'll have some tea."

His wife replies, "I just made some. It's still on the stove."

The coffee cup screams: NO ! I AM A COFFEE CUP ! NOT A TEA CUP ! DON'T DO IT !

But noone can hear him.

[[Tea it is]]

[[The man changes his mind again and has coffee]]

[[Tea it is]]:

He pours the coffee down the sink and rinses out the cup. He pours in some hot tea instead.

What does the coffee cup think about this? It does not. It no longer thinks at all. It is back to being just... a coffee cup.

The End.

[[The man changes his mind again and has coffee]]:

The man says aloud, "Nevermind. I'm running late."

"Whew, that was a close one. I don't think it be right, carrying tea. It's just... not in my nature."

[[The man heads to work]]

[[The man likes cream in his coffee]]:

The man likes cream in his coffee, so he pours some in.

"I'm being diluted by a white liquid!? It's not bad though."

The man stirs the drink.

The coffee cup laughs with delight. Oh. He is ticklish !

[[The man heads to work]]

[[The man heads to work]]:

The man grabs his keys, celphone, and coffee cup, and heads out the door to work.

The coffee cup is momentarily blinded by the sun. It is so bright outside, much brighter than indoors. And it is relecting off of the snow covering the man's yard. But it knows it is well insulated for his trip, and his contents well protected from the frigid winds.

[[The man falls on the icy sidewalk]]

[[The man gets into his car and heads to work]]

[[The man falls on the icy sidewalk]]:

@set FellOnIceFlag=1

set ("coffee", get("coffee") / 2 );

{if coffee<1: [[Finish]](YouLose)}

The man's shoes lose grip on the ice and he topples down. His coffee cup goes flying, and the lid pops off when it hits the sidewalk. Half of it is spilled, forever lost.

The coffee cup cries in pain, and feels dizzy, but it survives. It begins to question it's own mortality.

[[Head to work]](The man gets into his car and heads to work)

[[The man gets into his car and heads to work]]:

The man gets to his car, and into it as well. He places the coffee cup in the cup-holder of the car.

"I feel very safe here. Very secure indeed. Looks like we are going a bit on an adventure."

[[The man arrives at work]]

[[The man stops at 7-11]]

[[The man has a car accident]]

[[The man stops at 7-11]]:
if (squiffy.get("FellOnIceFlag") == 1) {
squiffy.story.go("711hefellearlier");
}
else {
squiffy.story.go("711nofallearlier");
}

[[711hefellearlier]]:

@set coffee=100

The man stops at the 7-11.

He tops-off his coffee.

" I feel rejuvinated ! "

[[The man heads to work]](The man arrives at work)

[[711nofallearlier]]:

@set Donut=1

The man stops at the 7-11.

He grabs a donut to eat at work.

[[The man heads to work]](The man arrives at work)

[[The man arrives at work]]:

{if seen The man stops at 7-11:{manLate}}{else:{manOnTime}}

[[manLate]]:

@set Late=1

The man arrives at work. He is late.

His boss warns him not to be late again.

[[Sit at desk]]

[[manOnTime]]:

The man arrives at work. He is almost late, but made it just in time.

[[Sit at desk]]

[[Sit at desk]]:

if (squiffy.get("Donut") == 1) {
squiffy.story.go("eatDonut");
}
else {
squiffy.story.go("NoDonutToEat");
}

[[eatDonut]]:

set ("coffee", get("coffee")-10 );

{if coffee<1: [[Finish]](YouLose)}

He walks over to his desk and sits down. As he eats his donut, he drinks the coffee.

[[He has to use the bathroom]]

[[NoDonutToEat]]:

set ("coffee", get("coffee")-20 );

{if coffee<1: [[Finish]](YouLose)}

He drinks some of the coffee.

[[He has to use the bathroom]]

[[The man has a car accident]]:

@set Late=1

The man is driving to work, and he picks up the cup to have a sip. Suddenly, the person in front of him stops his vehicle. The man slams the brakes and grabs the steering wheel with both hands. The cup goes flying. The man's car slides on the slushy road and bumps into the vehicle in front.

The coffee cup lands on it's side on the seat. A little gets out before than man can right it and put it back in the car-cupholder.

"That was frightful, but kind of exhilirating. I think I even did a double backflip!"

set ("coffee", get("coffee") - 20 );
{if coffee<1: [[Finish]](YouLose)}

[[The man arrives at work]]

[[He has to use the bathroom]]:

x

[[Finish]]:

x

Dennis Carlyle
It seems that the if/else in Squiffy can be 'picky' and inconsistent. There may be some kind of bug involved.

If you leave a space between "<" and "1", like below, then the code will do what it's supposed to, as written: It will display a link named "Finish". When it's clicked, the link takes the script to a section called "YouLose". (But I don't see any section called "YouLose" in the code you posted.)

<!-- comment: same code, but with a space added: -->
{if coffee< 1: [[Finish]](YouLose)}

TyCamden
Thank you. It works now, but ... it does not do what I was hoping.

How do I get the story to jump to Finish when the coffee is < 1 ? As it stands now, it just prints a Finish option which the reader can ignore.

Dennis Carlyle
TyCamden wrote:Thank you. It works now, but ... it does not do what I was hoping.

How do I get the story to jump to Finish when the coffee is < 1 ? As it stands now, it just prints a Finish option which the reader can ignore.


You could try just adding an "if" in Javascript in every section you want to check the value of 'coffee'. So the first line in those sections would be:


if (squiffy.get("coffee") < 1) {
squiffy.story.go("YouLose");
}


If coffee is > 0, then Squiffy will ignore the "story.go" part, and go on with the rest of what's in the section.

Or . . . you could create a 'Master' section, and put that if statement only in the Master. Then the value of coffee is automatically checked every time Squiffy goes to a new section.


[[]]:
if (squiffy.get("coffee") < 1) {
squiffy.story.go("YouLose");
}

Bluevoss
This is really cool, this last bit you posted about the master section. However, I've never been able to get this to work. For example, the following is code that will decrement on every loop and (presumably) fall out when it hits zero.

[[init]]:
@set score = 3

[[start this thing]](begin)

[[begin]]:

in begin section
@dec score

[[begin]]

[[YouLose]]:
game ends

[[]]:
score:{score}

if (squiffy.get("score") < 1)
{squiffy.story.go("YouLose");
}


Now, this is pretty much a copy of the master code you sent, changed to reflect my own variables. The thing is, I'm getting the following response for every call of the code in the master...

if (squiffy.get("score") < 1)
null


Tell me about the rabbits, George...

TyCamden
I figured it out !

The key was to put each choice in a *squiffy*-code IF at the send of each section.

For example, the Car Accident section BEFORE:

[[The man has a car accident]]:

@set Late=1

The man is driving to work, and he picks up the cup to have a sip. Suddenly, the person in front of him stops his vehicle. The man slams the brakes and grabs the steering wheel with both hands. The cup goes flying. The man's car slides on the slushy road and bumps into the vehicle in front.

The coffee cup lands on it's side on the seat. A little gets out before than man can right it and put it back in the car-cupholder.

"That was frightful, but kind of exhilirating. I think I even did a double backflip!"

set ("coffee", get("coffee") - 20 );
{if coffee<1: [[Finish]](YouLose)}

[[The man arrives at work]]


and AFTER/FIXED:

[[The man has a car accident]]:

@set Late=1

set ("coffee", get("coffee") - 20 );

The man is driving to work, and he picks up the cup to have a sip. Suddenly, the person in front of him stops his vehicle. The man slams the brakes and grabs the steering wheel with both hands. The cup goes flying. The man's car slides on the slushy road and bumps into the vehicle in front.

The coffee cup lands on it's side on the seat. A little gets out before than man can right it and put it back in the car-cupholder.

"That was frightful, but kind of exhilirating. I think I even did a double backflip!"

{if coffee< 1: [[Finish]](YouLose)}

{if coffee>= 1: [[The man arrives at work]]}


Full Code (so far):

@start intro

[[intro]]:
@set coffee=100
@set FellOnIceFlag=0
@set Donut=0
@set Late=0

@title The Coffee Cup

A man takes his plastic coffee cup from the cupboard. His favorite one. It is insulated to keep his coffee warmer, longer. It is black, and without design, serious and businesslike. And a handle with a comfortable grip.

He fills his coffee cup. It is pleased.

"Man, do I feel good. But, where am I? What am I? I appear to be a coffee cup. But... I have no memory before this one. Well... what happens now?"

[[The man heads to work]]

[[The man likes sugar in his coffee]]

[[The man decides to drink tea]]

[[The man likes sugar in his coffee]]:

The man likes sugar in his coffee. He opens a pack, and dumps it in.

"What is this powder that is being poured into me? It is so sweet. But... how am I tasting it? Or seeing anything? I don't have facial features. Not even a mouth. So, I cannot he heard or understood. HEY! MAN WITH THE POWDER! Nothing."

[[The man heads to work]]

[[The man likes cream in his coffee]]

[[The man decides to drink tea]]:

The man says aloud, "I'm tired of coffee today. I think I'll have some tea."

His wife replies, "I just made some. It's still on the stove."

The coffee cup screams: NO ! I AM A COFFEE CUP ! NOT A TEA CUP ! DON'T DO IT !

But noone can hear him.

[[Tea it is]]

[[The man changes his mind again and has coffee]]

[[Tea it is]]:

He pours the coffee down the sink and rinses out the cup. He pours in some hot tea instead.

What does the coffee cup think about this? It does not. It no longer thinks at all. It is back to being just... a coffee cup.

The End.

[[The man changes his mind again and has coffee]]:

The man says aloud, "Nevermind. I'm running late."

"Whew, that was a close one. I don't think it be right, carrying tea. It's just... not in my nature."

[[The man heads to work]]

[[The man likes cream in his coffee]]:

The man likes cream in his coffee, so he pours some in.

"I'm being diluted by a white liquid!? It's not bad though."

The man stirs the drink.

The coffee cup laughs with delight. Oh. He is ticklish !

[[The man heads to work]]

[[The man heads to work]]:

The man grabs his keys, celphone, and coffee cup, and heads out the door to work.

The coffee cup is momentarily blinded by the sun. It is so bright outside, much brighter than indoors. And it is relecting off of the snow covering the man's yard. But it knows it is well insulated for his trip, and his contents well protected from the frigid winds.

[[The man falls on the icy sidewalk]]

[[The man gets into his car and heads to work]]

[[The man falls on the icy sidewalk]]:

@set FellOnIceFlag=1

set ("coffee", get("coffee") / 2 );

The man's shoes lose grip on the ice and he topples down. His coffee cup goes flying, and the lid pops off when it hits the sidewalk. Half of it is spilled, forever lost.

{if coffee< 1: [[Finish]](YouLose)}

{if coffee>= 1: [[coffeeSurvivesIce]]}

[[coffeeSurvivesIce]]:

The coffee cup cries in pain, and feels dizzy, but it survives. It begins to question it's own mortality.

[[Head to work]](The man gets into his car and heads to work)

[[The man gets into his car and heads to work]]:

The man gets to his car, and into it as well. He places the coffee cup in the cup-holder of the car.

"I feel very safe here. Very secure indeed. Looks like we are going a bit on an adventure."

[[The man arrives at work]]

[[The man stops at 7-11]]

[[The man has a car accident]]

[[The man stops at 7-11]]:
if (squiffy.get("FellOnIceFlag") == 1) {
squiffy.story.go("711hefellearlier");
}
else {
squiffy.story.go("711nofallearlier");
}

[[711hefellearlier]]:

@set coffee=100

The man stops at the 7-11.

He tops-off his coffee.

" I feel rejuvinated ! "

[[The man heads to work]](The man arrives at work)

[[711nofallearlier]]:

@set Donut=1

The man stops at the 7-11.

He grabs a donut to eat at work.

[[The man heads to work]](The man arrives at work)

[[The man arrives at work]]:

{if seen The man stops at 7-11:{manLate}}{else:{manOnTime}}

[[manLate]]:

@set Late=1

The man arrives at work. He is late.

His boss warns him not to be late again.

[[Sit at desk]]

[[manOnTime]]:

The man arrives at work. He is almost late, but made it just in time.

[[Sit at desk]]

[[Sit at desk]]:

if (squiffy.get("Donut") == 1) {
squiffy.story.go("eatDonut");
}
else {
squiffy.story.go("NoDonutToEat");
}

[[eatDonut]]:

set ("coffee", get("coffee")-10 );

He walks over to his desk and sits down. As he eats his donut, he drinks the coffee.

{if coffee< 1: [[Finish]](YouLose)}

{if coffee>= 1: [[He has to use the bathroom]]}

[[NoDonutToEat]]:

set ("coffee", get("coffee")-20 );

He drinks some of the coffee.

{if coffee< 1: [[Finish]](YouLose)}

{if coffee>= 1: [[He has to use the bathroom]]}

[[The man has a car accident]]:

@set Late=1

set ("coffee", get("coffee") - 20 );

The man is driving to work, and he picks up the cup to have a sip. Suddenly, the person in front of him stops his vehicle. The man slams the brakes and grabs the steering wheel with both hands. The cup goes flying. The man's car slides on the slushy road and bumps into the vehicle in front.

The coffee cup lands on it's side on the seat. A little gets out before than man can right it and put it back in the car-cupholder.

"That was frightful, but kind of exhilirating. I think I even did a double backflip!"

xxx

{if coffee< 1: [[Finish]](YouLose)}

{if coffee>= 1: [[The man arrives at work]]}


[[He has to use the bathroom]]:

x

[[Finish]]:

x

Dennis Carlyle
Bluevoss wrote:This is really cool, this last bit you posted about the master section. However, I've never been able to get this to work. For example, the following is code that will decrement on every loop and (presumably) fall out when it hits zero.

[[init]]:
@set score = 3

[[start this thing]](begin)

[[begin]]:

in begin section
@dec score

[[begin]]

[[YouLose]]:
game ends

[[]]:
score:{score}

if (squiffy.get("score") < 1)
{squiffy.story.go("YouLose");
}


Now, this is pretty much a copy of the master code you sent, changed to reflect my own variables. The thing is, I'm getting the following response for every call of the code in the master...

if (squiffy.get("score") < 1)
null


Tell me about the rabbits, George...


I'm afraid I can't get it to work, either. I suggested the Master section "IF" without testing it. In your code above, the Master section starts with a non-JS statement, so that won't work. (Javascript must come first.) However, if I put the JS {if (squiffy.get . . . } as the 1st line in the Master section, the script doesn't run -- no output. You could try making the IF test a function residing in Master section, but then you're sort of back to square one, since you have to call the function from each section.

TyCamden
I also could not get it to work using a Master section.

But this worked instead...

@set score = 3
score: {score}

[[begin]]
[[begin]]:
@dec score
score: {score}

{if score< 1 : [[YouLose]]}{else: [[again]](begin)}
[[YouLose]]:
game ends

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

Support

Forums