0 votes
by (730 points)

After the player has visited four specific passages and returns to the main passage (where all the links of these passages are), a statement with a link is supposed to display in this main passage that was not there before. To do so, I put a (set:) macro in each of these passages. For example, in the first passage they were supposed to visit, I put the following:

(set: $passageA to true)

And I did this with the other three passages, using variables like $passageB, $passageC, and $passageD. So in the main passage, I put the following:

(if: $PassageA is true and $PassageB is true and $PassageC is true and $PassageD is true) [After a long day of walking, you realize you are tired after your pace becomes weary and sluggish. You think about [[heading home->Home]].]

When I tested it, nothing happened. Did I commit a silly coding mistake of some sort? Or is this just a complete mess?

3 Answers

0 votes
by (63.1k points)
selected by
 
Best answer

Here's an example file you can play and download.

To download the source code:

  • On Windows (most browsers): right click -> save as
  • On Mac (most browsers): file -> save as

You can the import the resulting html file back into Twine to view the code.

Source code:

:: init [startup]
{
<!-- you should hide this with css in your final project, this is fast and dirty -->
(set: $passageA to false,
	$passageB to false,
	$passageC to false,
	$passageD to false
)
}

:: home
Visit these places to unlock the way forward:

[[The Gym]]
[[The Store]]
[[The Office]]
[[Neighbor]]

(if: $passageA and $passageB and $passageC and $passageD)[\
	[[Move on]].
]

:: The Gym
(set: $passageA to true)\
You went to the gym.

[[home]]

:: The Store
(set: $passageB to true)\
You went to the store.

[[home]]

:: The Office
(set: $passageC to true)\
You went to the office.

[[home]]

:: Neighbor
(set: $passageD to true)\
You went to a neighbor's house.

[[home]]

:: Move on
You did all your visits for the day!

 Note: The above code is written in twee notation.

by (730 points)
Thanks, this will help!
0 votes
by (63.1k points)

How are you returning to the main passage? Is it through the undo button on the top left corner of the screen, or through a link? 

Also, this code: 

(if: $PassageA is true and $PassageB is true and $PassageC is true and $PassageD is true) 

Can be simplified to this: 

(if: $PassageA and $PassageB and $PassageC and $PassageD) 

I also suggest setting all those variables to false in a startup-tagged passage, since the default starting values of variables is 0 in harlowe, and that can lead to hard to find bugs if you aren't extremely careful with how you're using them. 

by (730 points)
I return to the main passage through links. All the four passages have a link that leads to the main passage.
0 votes
by (159k points)

The simplest way to test if the conditional expression of your (if:) macro is valid is to temporary assign the related variables to true within the same Passage as the (if:) macro.

eg. To debug the Passage do something like the following.

(set: $PassageA to true)
(set: $PassageB to true)
(set: $PassageC to true)
(set: $PassageD to true)

(if: $PassageA and $PassageB and $PassageC and $PassageD)[After a long day of walking, you realise you are tired after your pace becomes weary and sluggish. You think about [[heading home->Home]].]

... you may notice some differences between your version of the (if:) macro call and my own:

1. I removed the "is true" check because they are not needed when checking if a value/variable is true or false.

(if: $variable)[This text will only appear if the variable equals true]

(if: not $variable)[This text will only appear if the variable equals false]

(if: $variableA and $variableB)[This text will only appear if both variables equal true]

(if: not $variableA and not $variableB)[This text will only appear if both variables equal false]

2. I removed the (white) space character you place between the close parentheses of the macro and the open square bracket of the associated hook. I did this because it is invalid even though the 2,x series of Harlowe has been changed to ignore it.

(if: $variable)[GOOD: because the is no white space between the close parentheses and the open square bracket.)

(if: $variable) [BAD: because the is white space between the close parentheses and the open square bracket.)

If the (if:) macro works correctly after the temporary change then the issue is that one or more of the related variables aren't being changed to equal true. Or the variables are being reset back to false before the passage with the (if:) macro is being revisited which could happen if you aren't doing the initialisation those variables within your startup tagged special passage. 

by (730 points)
I have done what you said, then tested if the (if:) statement actually works, but after I visit the four passages then come back to the main passage, the sentence with the "Home" link simply won't appear.
by (63.1k points)
The only thing I can think of is that you might have made a typo somewhere, I'm assuming you already checked that, but a double check never hurt anyone. If you're doing everything we said, you're not using the undo button or (undo:) macro, you're setting everything up in a startup passage, and the (if:) works in the same passage as the (set:)s, then something somewhere is causing the variable changes to either revert or to not happen in the first place. Can you run the game in test mode and keep an eye on the variables and see what they're doing?

Check any header- or footer-tagged passages you have, too.
by (730 points)
Is there some kind of a simple HTML file example that I could use, with this (if:) statement? I think I could then understand my problem better.
by (63.1k points)
I can put one together when I have time.
...