If else problem

Twine Version: 2.3.16
Story Format: 2.36.1

I am having a problem, with probably a very basic solution, however, I am not yet basic enough to figure it out.

In StoryInit, I have this:

<<set $Job to false>>

Then later on in my story, after the character realises they need a job, I want to add this to all passages that relate to businesses.

You enter the bank. What would you like to do?
<<if $job is false>><<button "&ensp; See the bank manager about a job &ensp;">><<minutes_incr 1>><<goto "Town Centre">><</button>
<<else>><<button "&ensp; See the bank manager &ensp;">><<minutes_incr 1>><<goto "Town Centre">><</button>>
<</if>>

But only the option See the bank manager is displayed, when the variable was set to false in StoryInit.

I tried if $job = false, but got an error
I tried if $job = ‘false’’, but got an error
I tried if $job is ‘false’, but got the same See the bank manager option as above
I tried if $job == false, but got the same See the bank manager option as above
I tried if $job == ‘false’, but got the same See the bank manager option as above

I’m missing something obvious, I just know it, but I can’t tell what it is.

A variable name is letter-case sensitive.

So the $Job variable (upper-case J) you defined in your StoryInit special passage, and the $job variable (lower-case j) you are evaluating in the <<if>> macro call are being treated as two different variables, and the 2nd variable hasn’t been defined (assigned a value) yet.

There are also a couple of minor issues with your <<if>> macro usage:

1: You are using the is comparison operator to evaluate a Boolean.

Which isn’t needed and adds an unnecessary step in that evaluation. The following are examples of the correct way to handle Boolean variables.

/* Checking if variable equals true */
<<if $job>>The job variable equals true<</if>>

/* Checking if variable equals false */
<<if not $job>>The job variable equals false<</if>>
or
<<if ! $job>>The job variable equals false<</if>>

2: You are checking for false when handling both possible states of a Boolean variable.

When using an <<if>> plus <<else>> combination to handle both true and false states of a Boolean the code generally reads better if you use the <<if>> macro to check for true, and use the <> macro to handle the false outcome.

<<if $job>>
The job variable equals true
<<else>>
The job variable equals false
<</if>>

3: You are using a <<goto>> macro within an interactive macro (<<button>>) that supports Passage Navigation.

4: The <</button>> end tag of your 1st <<button>> macro call is missing a > character.

The following is a variation of your original example with the about points applied to it, it also includes a <<nobr>> macro call and code formatting to make it a little easier to read.
(note: example is written in TWEE Notation)

:: StoryInit
<<set $job to false>>

:: Bank
You enter the bank. What would you like to do?
<<nobr>>
<<if $job>>
  <<button "&ensp; See the bank manager &ensp;" "Town Centre">>
    <<minutes_incr 1>>
  <</button>>
<<else>>
  <<button "&ensp; See the bank manager about a job &ensp;" "Town Centre">>
    <<minutes_incr 1>>
  <</button>>
<</if>>
<</nobr>>
2 Likes