Answering a question before leaving a room

My player finds he cannot leave a classroom until he has answered the question - 'Mary, Elizabeth, James. Who is next' I cannot find a way of letting the player enter an answer, or a way of checking whether or not the answer is correct. Can anyone help please?


Here's one way to do it:

<!--Saved by Quest 5.7.6404.15496-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Answer Before Leaving">
    <gameid>02400486-8b00-4140-9b02-0eac2a9fa15a</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
    <feature_asktell />
  </game>
  <object name="classroom1">
    <inherit name="editor_room" />
    <alias>classroom</alias>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="out" to="outside">
      <inherit name="outdirection" />
      <runscript />
      <script type="script">
        if (not HasAttribute(classroom1, "answered_correctly")) {
          msg ("\"You can't leave until you've answered the question!\" snaps the teacher.")
          DoTheQuestion
        }
        else {
          MoveObject (game.pov, this.to)
        }
      </script>
    </exit>
    <object name="the teacher">
      <inherit name="editor_object" />
      <inherit name="namedmale" />
      <speakto type="script">
        if (HasAttribute(classroom1, "answered_correctly")) {
          msg ("\"You may now go outside,\" says the teacher.")
        }
        else {
          DoTheQuestion
        }
      </speakto>
      <ask type="scriptdictionary">
        <item key="president presidents washington">
          msg ("\"George Washington was the first president of the United States,\" says the teacher.")
        </item>
      </ask>
    </object>
  </object>
  <object name="outside">
    <inherit name="editor_room" />
    <usedefaultprefix type="boolean">false</usedefaultprefix>
    <descprefix>You are</descprefix>
    <enter type="script">
      msg ("YOU HAVE WON!")
      finish
    </enter>
    <exit alias="in" to="classroom1">
      <inherit name="indirection" />
    </exit>
  </object>
  <verb>
    <property>speakto</property>
    <pattern>speak to; speak; talk to; talk; speak with; talk with; converse with</pattern>
    <defaultexpression>"You can't speak to; speak; talk to; talk; speak with; talk with; converse with " + object.article + "."</defaultexpression>
  </verb>
  <function name="DoTheQuestion"><![CDATA[
    msg ("<br/>\"What is the last name of the first president of the United States?\"")
    get input {
      result = LCase (result)
      if (result = "washington") {
        msg ("<br/>\"Correct!  You may now {command:go out:go outside}!\"  The teacher smiles.")
        classroom1.answered_correctly = true
      }
      else if (StartsWith(result, "george")) {
        msg ("<br/>\"I'm only looking for a last name,\" the teacher says.<br/><br/>( {command:Speak to the teacher} to try again.)")
      }
      else {
        msg ("\"Incorrect!\"  The teacher shakes his head.<br/><br/>( {command:Speak to the teacher} to try again.)")
      }
    }
  ]]></function>
</asl>

You can get fancy with the text input field, too:

  <function name="DoTheQuestion"><![CDATA[
    JS.setInterfaceString("TypeHereLabel", "Enter the last name of the 1st US president.")
    msg ("<br/>\"What is the last name of the first president of the United States?\"")
    get input {
      JS.setInterfaceString("TypeHereLabel", "Type here...")
      result = LCase (result)
      if (result = "washington") {
        msg ("<br/>\"Correct!  You may now {command:go out:go outside}!\"  The teacher smiles.")
        classroom1.answered_correctly = true
      }
      else if (StartsWith(result, "george")) {
        msg ("<br/>\"I'm only looking for a last name,\" the teacher says.<br/><br/>( {command:Speak to the teacher} to try again.)")
      }
      else {
        msg ("\"Incorrect!\"  The teacher shakes his head.<br/><br/>( {command:Speak to the teacher} to try again.)")
      }
    }
  ]]></function>

Thank you for your help. I have added the first script but the game will not run now. I get this:-

Failed to load game.
The following errors occurred:
Error: Error adding script attribute 'script' to element 'exit44': Function not found: ''

Can this be put right?


It sounds like something has gone afoul with your exit44...

If you open the game in code view and search for "exit44", you may see something screwy.

It sounds like you may have nested the pasted text inside of the exit44 element (or script), but that's just a guess.


EDIT

I'm silly.

Upon reflection, I bet exit44 is the exit you added this script to to which you added this script.

I tried fooling around with things, but I couldn't recreate that error.

Could you paste the code for exit44?


NOTE: If you don't name your exits, Quest will name them for you. You can click on the exit in question's attribute tab to see its assigned name.


(filler for getting my edited post, updated/posted)


don't worry about your game not opening/playing, all it (most of the time) means, is that something is wrong with your code, you can always get into your game code via simply right clicking on your game file and opening it up with a text editor software (notepad, wordpad, Apple: text editor, notepad++, etc), fix the coding issues, and your game will now be able to be opened/played again.


KV already covered it, but the basics (and most simple ways of doing it) are these:

  1. the 'get input' Script/Function: gets the typed-in input/value from the command-text box during game play by the person playing the game

for 'get input, 'ask/Ask', and a few other Scripts/Functions, your inputed/selected value is automatically by quest (hidden from you) stored into the built-in 'result' Variable VARIABLE, which you can then act upon. See example below

(otherwise, you have choices to choose from via menus, for the person playing the game to select, and you/your-coding can act upon those selected choices/values. Also, there's using Commands, which take/use/get the typed-in input/value from the command-text box during game play by the person playing the game, and be able to act upon those selected choices/values)

  1. the 'if' Script/Function, as this lets you do string comparison, for determining what is then to be done.

a quick example (in code):

<game name="example_game">
  <attr name="start" type="script">
    msg ("Type in '1' or '2', please")
    get input {
      if (result = "1") {
        msg ("You typed in: 1")
      } else if (result = "2") {
        msg ("You typed in: 2")
      } else {
        msg ("wrong input, please try again")
        do (game, "start")
      }
    }
  </attr>
</game>

Sorry, had to do Thanksgiving stuff.


You'll need this function:
image

JS.setInterfaceString ("TypeHereLabel", "Enter the last name of the 1st US president.")
msg ("<br/>\"What is the last name of the first president of the United States?\"")
get input {
  JS.setInterfaceString ("TypeHereLabel", "Type here...")
  result = LCase (result)
  if (result = "washington") {
    msg ("<br/>\"Correct!  You may now {command:go out:go outside}!\"  The teacher smiles.")
    classroom1.answered_correctly = true
  }
  else if (StartsWith(result, "george")) {
    msg ("<br/>\"I'm only looking for a last name,\" the teacher says.<br/><br/>( {command:Speak to the teacher} to try again.)")
  }
  else {
    msg ("\"Incorrect!\"  The teacher shakes his head.<br/><br/>( {command:Speak to the teacher} to try again.)")
  }
}

...and this script on your exit:

image

if (not HasAttribute(classroom1, "answered_correctly")) {
  msg ("\"You can't leave until you've answered the question!\" snaps the teacher.")
  DoTheQuestion
}
else {
  MoveObject (game.pov, this.to)
}

I forgot the speak to teacher bit:

image

if (HasAttribute(classroom1, "answered_correctly")) {
  msg ("\"You may now go outside,\" says the teacher.")
}
else {
  DoTheQuestion
}

Sorry for the delay replying. I’ve been away. The suggestions are very welcome and I’m very grateful for all your help.


Log in to post a reply.

Support

Forums