0 votes
by (2.5k points)
closed by

This is the code for an input box.

if (typeof window.customScripts == "undefined") {
	window.customScripts = {
		submitName: function(inputName) {
			//Get the value of the textbox at time of click
			var newName = $("input[name='" + inputName + "']")[0].value;
			//Find the hook node based on name and set the text inside
			$("tw-hook[name*='" + inputName + "']").text(newName);
			//Log the Change
			console.log(inputName + " changed.")

And this is what is in my passage.

(set: $rivalName to "")
You and [your unnamed rival]<fname|.

<input type="text" name="fname" value="Johnson">
<button type="submit" onclick="customScripts.submitName('fname')">Yes that's it</button>

(live:100ms)[(set:$rivalName = ?fname)]

The issue is that it gives me the error "?fname can't be stored."

The name changes but the string doesn't. How do I fix this??

http://twinery.org/forum/discussion/comment/6468/#Comment_6468 for reference.

(I hitting y'all with dem hard questions)

closed with the note: Found my answer.

2 Answers

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

The solution you linked to was written for Harlowe 1.x, and unfortunately Harlowe 2.x was deliberately changed so that you can no longer use a hook reference (the ?fname part) to access the Text contained within a named hook, so that solution doesn't work for that series.

I suggest you read the selected answer of the A way to have a text box on the page rather than an input box? question.


0 votes
by (2.5k points)


This is what worked!

if (typeof window.CustomScripts == "undefined") {
	window.CustomScripts = {
		updateVariable(inputName) {
			// Get the value from the input textbox at time of click.
			var value = $("input[name='" + inputName + "']")[0].value;
			// Update the variable.
			State.variables[inputName] = value;


<center>(set: $attack to (either: "v", "b") + (either: "v", "b") + (either: "v", "b") + (either: "v", "b") + (either: "v", "b") + (either: "v", "b"))(set: $counter to 5)You have |amount>[$counter] seconds left!
(live: 1s)[	(set: $counter to it - 1)(if: $counter is 0)[(go-to: "Attacked!")](replace: ?amount)[$counter]]
<input type="text" name="fname" value="">
<button type="submit" onclick="CustomScripts.updateVariable('fname')">Defend!</button></center>

What is in the passage^

(if: $fname is $attack)[You take no damage!
](else:)[You got hurt!]

Passage 2^

This solves both my problems. While I still can't use ?fname I was able to bypass it. and I just realized you just pointed me to the forum I got this from.....oof....