Howdy, Stranger!

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

How to offer choices to the player (variable name)

Hello
I'm struggling because in my story I'd like to offer choices to the player.
I want the player to choose the name of his/her friend, but instead of asking the player "what's your friend name?"
I want to make proposal such as
"Your friend is :
John
Alex
Mark"

If anyone can help me I can't find the solution anywhere....


Thank you so much!!

Comments

  • edited April 2016
    It's useful to put what story format you're using, as the syntax can vary. I'll assume you're using Harlowe.

    Do you want them to have a limited number of options, like you list in your post?

    If you'd like your player to be able to input anything, you could use this code:
    (put: (prompt: "What's your name?") into $name)
    

    This allows them to put whatever they want in, and it creates a variable for it. So then, whenever you type $name, it comes up with the player's input.

    Or, if you want them to have a limited number of options, you could use multiple passages. So you'd use
    [[Alex]] [[John]] [[Mark]]
    
    and each name would link to a new passage. In the new passage, you would create a variable for the name they have chosen;
    (set: $friendname to "Alex") Your friend is called $friendname.
    
    Then, you link each passage too the next chronological passage, and from then on you can use the variable $friendname to refer to their friend.

    Possibly, you could use the (Click-replace:) macro as well.

    This would look like:
    Your friend is:
    
    [John]<One|
    (Click-replace: ?One)[(set: $friendname to "John")Your friend is $friendname]
    [Alex]<Two|
    (Click-replace: ?Two)[set $friendname to "Alex")Your friend is $friendname]
    

    This is perhaps shorter but I think less neat, as the other names still remain on the page.
  • Hanzor wrote: »
    This is perhaps shorter but I think less neat, as the other names still remain on the page.
    The following solves that problem using a named hook:
    Your friend is: |name>[
    
    {(link: "John")[
    	(set: $friendname to "John")
    	(replace: ?name)[$friendname]
    ]}
    {(link: "Alex")[
    	(set: $friendname to "Alex")
    	(replace: ?name)[$friendname]
    ]
    }]
    
Sign In or Register to comment.