Making a hook appear after a variable is filled

Twine Version: 2.3.12
Story Format: Harlowe 3.2.1

I’m looking for a way to display the link to the next passage only after the player inputs the character name. The code below didn’t work (I was trying to make the link appear only after the variable $name is not null to work around this):

(set: $name to (prompt: "The name of the character is:", ""))
(if:$name is not "")[=
[Hello, $name!|Next passage]

Some help would be appreciated! I felt like this should be a simple matter.

As shown in the Link Markup documentation, a Mark-up based Link starts & ends with a matching set of non-nesting [[ and ]] characters. So the link part of your example should look something like…

[[Hello, $name!|Next passage]]

So if we apply the above information to your original example it would end up looking something like the following…

(set: $name to (prompt: "The name of the character is:", ""))
(if: $name is not "")[=
[[Hello, $name!|Next passage]]

note: If you plan to add other always visible content, or content that is shown based on some other condition, after the above Mark-up based Link then you will likely need to replace the [= symbol of the Unclosed hook mark-up with a standard Hook.

(set: $name to (prompt: "The name of the character is:", ""))
(if: $name is not "")[
[[Hello, $name!|Next passage]]
]
Other content that isn't part of the above condition.

Didn’t work. The link appeared even before the prompt appeared, and it reads as
Hello, o!

I tested the following Passage content in a new Harlowe v3.2.1 project, using both the Test and Play options, as well as the Publish to File option.

(set: $name to (prompt: "The name of the character is:", ""))
(if: $name is not "")[
[[Hello, $name!|Next passage]]
]

And each time I was shown the Prompt Dialog before any link was shown in the page, and if I entered a value into the prompt’s field then the link that was shown would include that value.
eg. if I entered AAA into the prompt’s field then the link’s text that appeared after I selected the OK button would read Hello, AAA!

Does the Passage contain any other content?
Are you using CSS to alter the styling of the page?
Are you using a custom effect when transitioning to that Passage?

I’m sorry. I have just found out that I forgot to include the 2-second delay that was in my passage form the start.

This is a text I wanted to display at first.
(after:2s)[(set: $name to (prompt: "The name of the character is:", ""))]
(if: $name is not "")[
[[Hello, $name!|Next passage]]
]

The passage content you posted above works for me, too. But once I put in the (after:2s) everything went haywire again.

When you use timer based macros like (live:) and (after:) the content you place within their associated Hooks is excluded from the standard processing of the Passage’s content, which is why the later (if:) macro is evaluated before the referenced $name variable is assigned the return value of the (prompt:) macro call.

So if you want the evaluation of the (if:) macro’s condition to be delayed until after the (set:) macro has assigned $name a value then you need to include that code inside the (after:) macro’s associated Hook.

This is a text I wanted to display at first.
(after: 2s)[{
	(set: $name to (prompt: "The name of the character is:", ""))
	(if: $name is not "")[
		[[Hello, $name!|Next passage]]
	]
}]
1 Like

That solves it. Thanks!