How to add a riddle system with consequences in a Quest Game

I’m making a game where you must answer a riddle to obtain a necessary item, and answering wrong depletes health slightly, How do I set this up?


Correction- How to add non-yes/no questions


I've played with a few different setups for implementing that kind of system.
You can use menus if you want to give defined answers for the user to choose from (basically a multiple-choice question).

To do this, you'd either set up a list as an attribute on an object and call it for the menu options (this lets you dynamically add or remove answers as the player does stuff), or you can use the Split function to create the options straight from the menu. The selected option is then returned as the "result" string, which you can use a switch (better for more options) or if statements to resolve. The code block would look something like this... (And you can use an attribute such as Sphinx.answerslist instead of a Split if you prefer that - dictionary lists in particular can make things more elegant, as they show the value and return the key, so you can show a long answer and return only the key afterwards.)

If all your incorrect answers do the same thing, you could also define only the correct answer in the cases, and have all the incorrect answers push to the default block.

msg ("Enter password... <br/>")
ShowMenu (Split("Answer1;Answer2;Answer3;Answer4")), false) {
  switch (result) {
    case ("Answer1") {
      msg("Correct!")
      Sphinx.appeased = True
    }
    case ("Answer2") {
      msg("Especially Incorrect...")
      player.health = player.health - 2
    }
    default {
      msg("Answers 3 and 4 are also incorrect and push here as they're not defined as cases...")
      player.health = player.health - 1
    }
  }
}

You can also have the user type in an answer if you have the command bar active. For that, you'd use the "Get input" block, which saves the user's reply to the "result" string. You can then use an if statement to check if they input the correct answer. I'd strongly recommend using the LCase(result) function so that it's case insensitive, unless you care a lot about case in the answer. The code block would look something like this...

  get input {
    if (LCase(result) = "answer") {
      msg ("Correct!")
      Sphinx.appeased = True
    }
    else {
      msg("Incorrect...")
      player.health = player.health - 1
    }
  }

This is covered - more or less - in the docs:
http://docs.textadventures.co.uk/quest/asking_a_question.html


Log in to post a reply.

Support

Forums