Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

My Javascript won't work when I "play" (but does when I test from that one screen)

edited September 2015 in Help! with 2.0
I'm using the name script from over here and so I have it set up that my JavaScript says:
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[title*='" + inputName + "']").text(newName);
//Log the Change
console.log(inputName + " changed.")
}
};
};

and my first passage says:
Welcome to Scion, an interactive horror game where your choices dictate who loves you and who hates you, where you end up at the end and even who lives and who dies - including yourself. There are $endings endings to this game, will you find them all?

To begin, let's answer some establishing questions.

What's your name?

You're [not sure...]<fname|.

<input type="text" name="fname" value="Sam">
<button type="submit" onclick="customScripts.submitName('fname')">is my name!</button>

(link: "That's me!")[(set:$name = ?fname)Your name is $name.

Next->Gender]

For some reason, when I click "test story starting here" or just plain "test" it works perfectly! You put your name in (Chloe, for example) and it works!

When I click "play this story" pressing the button for "is my name!" doesn't work.

Am I screwing up somehow?

Comments

  • The problem seems to be this line:
    $("tw-hook[title*='" + inputName + "']").text(newName);
    

    If you change it to
    $("tw-hook[name='" + inputName + "']").text(newName);
    

    Then it works in both debug and normal mode. I guess when debugging it also sets the title attribute to the same value as the name.
  • I guess when debugging it also sets the title attribute to the same value as the name.
    Yes, it seems that the Harlowe engine uses an element's title attribute to pass information to it's built-in debugger. Because of this you can't rely on it being there during the Play or Publish to File option.
  • Ah! Thank you so much. I never would've figured that out (but you shoulda seen me tryna troubleshoot this oh my god). Thank you <3 I can progress now!
  • The way I spotted the problem was to publish the story and then use Firefox's web inspector to look at the generated HTML. from that I was able to see that the tw-hook element had a name attribute, but not title.

    hopefully this'll help troubleshooting if you run into a similar problem in the future.
Sign In or Register to comment.