Say command

Sorry, I'm not sure how to search the forum. I would like to do a simple Say command, which acts on the words spoken by the player, such as a spell. I am not sure how to set this up, it's going to be room specific. Thank you for any help!


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


quest doc site main page:

http://docs.textadventures.co.uk/quest/

the 'Command' Element uses/takes-in/gets user input (as does the 'get input' Script/Function, as some of the few ways of getting/using the users input):

http://docs.textadventures.co.uk/quest/elements/ (the Elements, to find this link, its at the bottom of the main page of the doc, in/under the 'reference' section/category, so its a bit hidden/hard-to-find, lots of other useful links are in/under the 'reference' section/category as well, like the Attribute Types, and etc stuff)

http://docs.textadventures.co.uk/quest/elements/command.html (the 'Command' Element)

here's the tutorial main page:

http://docs.textadventures.co.uk/quest/tutorial/

here's the 'Command' section on the tutorial:

http://docs.textadventures.co.uk/quest/tutorial/custom_commands.html


so, about Commands:

the 'pattern' String Attribute of a 'Command' Element, is what is used to match-up/parse with what the user types in as their input

for example

<command name="custom_help_command">

  <pattern>help</pattern>

</command>

when someone playing the game, types in 'help', this activates/runs my 'custom_help_command' Command

this first word in the 'pattern' String Attribute of a Command, must be unique, so that quest can identify which Command it is that you want, which is why I like calling this first word as the 'activator' word

for example of why it must be unique

<command name="custom_help_command">

  <pattern>help</pattern>

</command>

<command name="custom_help_command_2">

  <pattern>help</pattern>

</command>

we type in 'help', but what Command does it activate? The 'custom_help_command' Command or the 'custom_help_command_2' Command?


now, just having a single 'activator' word as your Command's pattern, doesn't take in any input data from the user, for it to use within its scripting (we'll get to the Command's scripting/actions later on / further down, so let's just ignore it for now)

so, if we want to get/use the user's typed-in input data:

<command name="custom_help_command">

  <pattern>help #text#</pattern>

</command>

now, the person playing the game can type this in (an example):

help controls // help[SPACE]controls

which matches up with the Command's pattern:

activator word (help), [SPACE], user input (controls)

if we typed-in this, it wouldn't match up with the Command's pattern:

helpcontrols

as our Command's pattern, has a [SPACE] between its activator word (help) and its user input part/segment/section of its pattern (which for this example, we type-in input: controls), but our typed-in input does NOT have that [SPACE] in it

we can get/use multiple inputs as well:

<command name="custom_mix_command">

  <pattern>mix #text# with #text# and #text#</pattern>

</command>

you type in (for example):

mix water with sugar and vitamins


you can generally use whatever structure/pattern you want for the Command's pattern, for example:

<command name="custom_mix_command">

  <pattern>mix #text# #text# #text#</pattern>

</command>

and typing in (for example): mix water sugar vitamins, would work fine too

I myself personally, like having my Command's pattern be at least somewhat similar to normal (american english) grammered sentences, but that's my own personal preference


alright, now about how the input matching works:

the '#XXX#' in a Command's pattern is telling quest that, that segment/part/section of the user's input is to be taken and stored as an 'argument (data)' into its own special built-in 'Parameter' Variable VARIABLES (which I'm going to cover right now, as I've not done so yet, lol), which the Command's scripting can then use within it

the names/labels of the "Parameter' Variable VARIABLES, MUST be:

text
or
textXXX

the 'XXX' can be whatever you want, in other words, it must start with 'text'

some quick examples:

text
text2
text_2
textparameter
text_parameter

but within the Command's pattern, you MUST encase the 'text' Parameter with the hashtags, examples:

<command name="custom_help_command">

  <pattern>help #text#</pattern>

</command>

--------

<command name="custom_help_command">

  <pattern>help #text2#</pattern>

</command>

----------

<command name="custom_help_command">

  <pattern>help #text_2#</pattern>

</command>

------

<command name="custom_help_command">

  <pattern>help #text_parameter_2#</pattern>

</command>

-----

<command name="custom_help_command">

  <pattern>help #text_abcdefghijklmnopqrstuvwxyz#</pattern>

</command>

now, there's another type of special built-in Parameter for Commands, as well:

object
or
objectXXX

and within the Command's pattern, remember it needs to be encased in the hashtags:

#object#
or
#objectXXX#

so, what's the difference between using: text vs object, ???

well, using 'text', means that quest will take the user's input as simply being a String Value Data Type (aka, as "text")

whereas, using 'object' means that quest will look for an 'Object' of that input, within the room you're currently within, when the user types in their input command, which if it finds such an Object, that Object's address/reference/pointer will be stored into its 'object' Variable VARIABLE for use by the Command's scripting

so, there's a quite a bit of a difference between using 'text' vs 'object', but this is getting into a bit more complex stuff, that will be hard to explain in more detail, so I'm not going to try doing here for this post.

Also, you can use both 'text' and 'object' Parameters in the same Command, as well


Also, you can have multiple patterns as well, via using the semicolon in your Command's 'pattern' String Attribute:

(this gets a bit into the complexity/issues of parsing-logic, which in simple guidance, start with the most complex pattern to the least complex pattern)

an example (with the scripting):

(see a bit further below, past this part/section, for the explanation of how the scripting and its use of the inputs works)

you can type in (for example, for this example Command):

'help controls' // or: 'help stats' // or: 'help combat' // or: etc etc etc of my example help topics
or
'help'
or
'h'

<command name="custom_help_command">

  <pattern>help #text#;help;h</pattern>

  <script>

    if (text = null) {
      show menu ("Help Topic?", Split ("controls;stats;combat;magic;stealth;diplomacy;items;equipment", ";"), false) {
        switch (result) {
          case ("controls") {
            msg ("blah blah blah about the game's controls")
          }
          case ("stats") {
            msg ("blah blah blah about the game's stats")
          }
          // ETC ETC ETC 'cases' (combat, magic, stealth, diplomacy, items, equipment)
        }
      }
    } else {
      switch (text) {
        case ("controls") {
          msg ("blah blah blah about the game's controls")
        } case ("stats") {
          msg ("blah blah blah about the game's stats")
        }
        // ETC ETC ETC 'cases' (combat, magic, stealth, diplomacy, items, equipment)
        default {
          msg ("wrong input: your input doesn't match up with any of the help topics (controls, stats, combat, magic, stealth, diplomacy, items, and equipment) available, try again")
        }
      }
    }

  </script>

</command>

anyways, now let's get to the Command's scripting itself and how it uses those inputs (if you got them for the Command)

here's some examples (using just the 'text' Parameter type):

<command name="custom_help_command">

  <pattern>help</pattern>

  <script>

    show menu ("Help Topic?", Split ("controls;stats;combat;magic;stealth;diplomacy;items;equipment", ";"), false) {
      switch (result) {
        case ("controls") {
          msg ("blah blah blah about the game's controls")
        }
        case ("stats") {
          msg ("blah blah blah about the game's stats")
        }
        // ETC ETC ETC 'cases' (combat, magic, stealth, diplomacy, items, equipment)
      }
    }

  </script>

</command>

// you type in 'help'
// output: a pop-up menu of help topic choices
// you select the 'controls' help topic menu item
// output: blah blah blah about the game's controls

-----------------------------------------

<command name="custom_help_command">

  <pattern>help #text_topic_parameter#</pattern>

  <script>

    switch (text_topic_parameter) {
      case ("controls") {
        msg ("blah blah blah about the game's controls")
      } case ("stats") {
        msg ("blah blah blah about the game's stats")
      }
      // ETC ETC ETC 'cases' (combat, magic, stealth, diplomacy, items, equipment)
      default {
        msg ("wrong input: your input doesn't match up with any of the help topics (controls, stats, combat, magic, stealth, diplomacy, items, and equipment) available, try again")
      }
    }

  </script>

</command>

// you type in: help controls
// output: blah blah blah about the game's controls

lastly:

there's global Commands (which can be activated from any where within your game) and there's local Commands (which will ONLY activate if you're within the same room as the Command that you want to activate)

if you add/create a Command to a specific room, then it's that room's local Command

if you add/create a Command NOT to a specific room, then it's a global (game wide) Command

I'm not sure exactly how this is done with the GUI/Editor, as I hardly ever use it (and am too lazy to do so), but hopefully you can figure it out

here's how it looks within the entire game code (within the simple default new game code, for an example):

<asl version="550">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <game name="NAME_OF_GAME">

    <!--
    blah Attributes (gameid, author, version, firstpublished, category, description, subtitle, difficulty, cruelty, start, pov, etc etc etc)
    -->

  </game>

  <object name="room">

    <inherit name="editor_room" />

    <command name="example_local_command">

      <pattern>local</pattern>

      <script>

        msg ("EXAMPLE LOCAL COMMAND")

      </script>

    </command>

  </object>

  <object name="player">

    <inherit name="editor_object" />
    <inherit name="editor_player" />

    <attr name="parent" type="object">room</attr>

  </object>

  <command name="example_global_command">

    <pattern>global</pattern>

    <script>

      msg ("EXAMPLE GLOBAL COMMAND")

    </script>

  </command>

</asl>

A proper say command that does something useful is very difficult as your NPCs have to understand anything the player may choose to type. However, it sounds like your requirements are more modest if you want to cast spells; all you need to do is have a command for each spell.

So you could have one command with the pattern "say lumos", when the player types that, light happens.

Take a look here too:
http://docs.textadventures.co.uk/quest/zombie-apocalypse-spells.html


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums