Howdy, Stranger!

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

Character or Item Naming

Ok so I'm fairly new to twine but i've seemed to have gotten the hang of the basics. In my story the character has the option to choose their gender(doesn't affect the story in any way) and i haven't seen the question asked on how to allow the characters to choose their own names. Is there a way to do this, in the same way you would type out your name for a game or website? Im using Twine 2 on Harlowe if that helps.

Comments

  • CX3CX3
    edited February 2016
    Okay, i´m new to twine, but already find some answers. I hope i can contribute to solve your problem: I used this in Twine Harlow:

    Enter this in your first passage:
    Your Name: []<fname|
    <input type="text" name="fname" value="Unknown"><button type="submit" onclick="customScripts.submitName('fname')">Update Name</button>
    
    Your Job: []<fjob|
    <input type="text" name="fjob" value="Unknown"><button type="submit" onclick="customScripts.submitName('fjob')">Update Job</button>
    
    [[Second Passage]]
    
    (live:100ms)[(set: $yourName = ?fname)(set: $yourJob = ?fjob)]
    

    then you may access the input your secound passage using this variables:
    Your Name: $yourName
    Your Job: $yourJob
    

    Or course you can rename $yourJob to $playerGender. Also some of the text is displayed for the user, you may want to change that as well. e.g. instead of "Your Job:" you enter "Your gender" and instead of "Update Job", you write: "Confirm Gender" or something.

    Also, for this to work, you need javascript code. Enter it in the javascript section:
    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.")
        }
      }; 
    };
    

    Don´t ask me about javascript thought... I guess it somehow gets triggert when the user enters name / job / gender whatever.

    Hope that code, that works for me, can be used by you and then adapted to serve your purpose.

Sign In or Register to comment.