Player wanting to change name after asking for confirmation?

I want to give the player the ability to choose their name. But to make sure that it's not wrong I want to confirm it. How do I turn the player back into answering the name if they pick "no"? Can I even put the player back and erase the player's first choice of "Name"? I just want to make sure that they can have the name they want.

It's nice to meet someone so interesting as...

Well...

[[What is your name?]]

[[What is your name?]]:

<textarea id="text_first"></textarea>

[[Is this the name you want?]](Click here when done)

[[Click here when done]]:

    squiffy.set("Name", jQuery("#text_first").val());

So your name is {Name}?

[Yeah]
[No]

[No]:
[[What is your name?]]

[Yeah]:
How nice to know your name, {Name}!

The problem is that it keeps the first chosen name and doesn't update it. I want to maybe be able to go back and change it fully replacing the "Name" with the new one that the player has chosen.


I suspect that the problem is that you've got 2 textareas with the same ID, and when you do that jQuery only finds the first.

If the player scrolled up and changed their name in the first input, then it would let them change it.

One way to do this would be to remove the first form field, so that it isn't there for jQuery to find the second time. Or to replace it with plain text. For example, changing the javascript line to:

    jQuery("#text_first").replaceWith(function () {
        squiffy.set("Name", jQuery(this).val());
        return ($('<p>').text($(this).val()));
    });

Edit: Missing brackets. Sorry about that.


Now it doesn't want to continue forward to the question of keeping the name?

Well...

[[What is your name?]]

[[What is your name?]]:

<textarea id="text_first"></textarea>

[[Is this the name you want?]](Click here when done)

[[Click here when done]]:

    jQuery("#text_first").replaceWith(function () {
        squiffy.set("Name", jQuery(this).val());
        return ($('<p>').text(this.val()));
    });

So your name is {Name}?

Did I miss something?


mrangel's JS answers are consistently brief, elegant, and seemingly magical. I'm only recently learning that there's a difference between inefficient and readable JS and efficient magic-spell-looking JS. I'm sorta getting the hang of the former. Sorta.

I always try to find a pure Squiffy or mostly Squiffy answer for everything. If you don't mind clearing your screen with @clear, this solution allows the player to change their name or continue on:


Well...

[[What is your name?]]

[[What is your name?]]:
@clear

<input id="text_first">

[[Is this the name you want?]](Click here when done)

[[Click here when done]]:

    squiffy.set("Name", jQuery("#text_first").val());

So your name is {Name}?

[Yeah]
[No]

[No]:
[[What is your name?]]

[Yeah]:
How nice to know your name, {Name}!

Sorry, my bad. Not sure how I managed to make an error like that; but in the last script I posted there was a this that should be $(this). I edited it now.


An alternative solution would be changing it so that if there's more than one #text_first it takes the last one; by changing jQuery('#text_first') to jQuery('input#text_first').last().


The code from both IfforClassroom and mrangel works just as well. I just want the player to see the small message before the question so mrangel's answer worked the best for me. I think that using @clear makes it harder for the player to remember what was just talked about. But I do think that it could work for the people that don't want to make the story out of too much code.

Thank you for the help!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums