0 votes
by (160 points)

I'm having difficulty adding a simple text input field to one of my passages. I'm using Snowman for this project. The input field, upon changing, should update a `riddleAnswer` variable with the value of the input field.

<% if (!riddleDoorBlock) { %>

	As you approach the door with a face on it, the face starts speaking!

	"AH. ANOTHER ADVENTURER ON A QUEST FOR TREASURE."

	"I SUPPOSE I COULD LET YOU PASS, BUT I'LL NEED YOU TO ANSWER A RIDDLE FOR ME."

	The face pauses, clearly thinking of a riddle to give to you. Finally, it speaks.

	"GIVE ME FOOD AND I WILL LIVE. GIVE ME WATER AND I WILL DIE. WHAT AM I?"

	Your Answer: <input type="text" name="riddle" onchange="riddleAnswer=this.value">

	[[Confirm|Door's Response]]
	
<% } else { %>

	"LIKE I SAID, YOU CANNOT GO THIS WAY ANYMORE. BEGONE."
	
	[[Back|Bronze Chamber]]
	
<% } %>

I thought I could simply add an HTML element like `<input type="text" name="riddle" onchange="riddleAnswer=this.value">` but it just renders as plain text.

What's the right way to format this?

1 Answer

+1 vote
by (159k points)
selected by
 
Best answer

The solution is simple, remove the TAB character based indentation from the passage content.

<% if (!riddleDoorBlock) { %>

As you approach the door with a face on it, the face starts speaking!

"AH. ANOTHER ADVENTURER ON A QUEST FOR TREASURE."

"I SUPPOSE I COULD LET YOU PASS, BUT I'LL NEED YOU TO ANSWER A RIDDLE FOR ME."

The face pauses, clearly thinking of a riddle to give to you. Finally, it speaks.

"GIVE ME FOOD AND I WILL LIVE. GIVE ME WATER AND I WILL DIE. WHAT AM I?"

Your Answer: <input type="text" name="riddle" onchange="riddleAnswer=this.value">

[[Confirm|Door's Response]]
	
<% } else { %>

"LIKE I SAID, YOU CANNOT GO THIS WAY ANYMORE. BEGONE."

[[Back|Bronze Chamber]]
	
<% } %>

As noted in the story format's documentation, Snowman supports using a variation of the Markdown language to format the content of a Passage, and in Markdown lines starting with a TAB character indicate that that line is a code block.

by (160 points)
This fixed my problem! I was stuck because I was in a JavaScript-formatting mindset, where indents are used to organize things.
by (159k points)
The code between the <% and %> or  between the <%= and %> in a Passage is JavaScript, everything else is either Markdown, HTML or a link.
...