Howdy, Stranger!

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

Fill in the Blank type Question

I'm making a game where the "dungeon master" asks the player a question and the player is required to write an answer in a prompt. My problem is getting the code to work where, depending on the answer given, the player will either go to the "correct answer" passage or "incorrect answer" passage. BTW I'm using Harlowe to make this game.

This is the code I'm using.
(set: $easy1answer to (prompt: "Give your answer:"))

(if: $easy1answer contains yesterday)Correct Easy 1]
(else:)Incorrect Easy 1]

Comments

  • Also, this is the result of testing this part of my game.

    yesterday is not defined►
    There's nothing before this to do (else:) with.
  • Please use the C button in the Comment field's tool-bar to wrap your code examples with code tags, it makes them easier to read/find.

    There are a couple of issues with your example:

    1. The (prompt: ) macro returns a String value which means that any value you compare it to also needs to be a String.
    (if: $easy1answer contains "yesterday")
    
    2. String compares are case-sensitive which means "Yesterday" does not equal "yesterday", and you can't control what casing the Reader will enter their responses in.

    One technique used to get around this issue is to temporary convert the Reader's response to lower-case before comparing it, and you can use the Javascript String toLowerCase() method to do this.
    (if: $easy1answer.toLowerCase() contains "yesterday")
    
Sign In or Register to comment.