Howdy, Stranger!

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

Displaying conditional text/options if a player enters a certain name

Hello - probably a very stupid question, but this is Day One for me so it's bound to be!

Midway through my game, I have the user prompted to enter their name. If they have received a clue early on, I would like them to receive additional options if they enter a specific name. Let's say the name that will open an additional option is 'gimli'. So far I have:

---

(set: $name to (prompt: "Text asking the player to enter their name"))

You are (print: $name).

(if: $name = gimli)newpassage](else:)usualpassage]

---

I've tried putting in more, and fewer, brackets, but the result is the same - I get a screen with the attached image.

--

If you are able to help me, please do - I've got a lot of other things working, but this is confusing me horribly.

Very grateful for your help,

Frog

Comments

  • edited July 2016
    The are two mistakes in your example:

    1. As stated in the (prompt:) macro documentation, the value returned by that macro is a String. This means that any value you compare to your $name variable also needs to be a String.

    2. In TwineScript (and Javascript) a single equals sign = operator is used to represent assignment, whereas a double (or triple) equals sign == (===) operator is used to represent comparison. Using the wrong equal sign operator is a common mistake so Harlow suggests using the to operator (for assignment) and the is operator (for comparison) instead.

    This means that the expression in your (if:) macro is trying to assign the value gimli (of unknow data type) to your $name variable and you are getting the "not define" message because Harlowe cant find something defined gimli.

    The following is a corrected version of your example:
    (set: $name to (prompt: "Text asking the player to enter their name"))
    
    You are (print: $name).
    
    (if: $name is "gimli")[[[that's interesting|newpassage]]](else:)[[[same as usual|usualpassage]]]
    
  • edited July 2016
    Strings are case sensitive so you'll need to do an "or" for "Gimli" with a capital as well, but I don't know how to do that in Harlowe.
  • That's extremely helpful - thank you! Very patiently explained, and has led me to properly understand a few more basic concepts. Thanks both!
Sign In or Register to comment.