look/description/etc-like-responses handling

assuming this works perfectly (hadn't tested it yet) ... here's a possible design (probably/likely not the best of course)

(and I don't like my labeling/naming of things, as 'response' is usually more associated with dialogue/conversation responses)

this actually reduces the work greatly (assuming it works perfectly, lol), as this is really versatile. If you want, you can just add default responses to the 'response_object' Object's 'default_response_stringlist_attribute' Stringlist Attribute. Or, you can add terms (what someone would type in for the 'response #text#', our 'look/examine' custom 'response_command' Command) to the Room Object's 'response_stringdictionary_attribute' Stringdictionary Attribute, and add in the response for those terms, as well. Lastly, you can have your Objects within the Room Object have the same as the prior sentence. You can decide on how much detail (how many Objects and/or layer of Objects have info/details/descriptions/responses/default-repsonses to them). Also, I can add/adjust my code for also being able to do the same for the 'response_object' Object, having a Stringdictionary Attribute with terms and their responses, if you only want to deal with a single Object to handle all of the possible terms one playing the game might try or that you mention about as terms they can get more details (or a default response) about.

<command name="response_command">
  <pattern>response #text#</pattern>
  <script>
    if (Contains (game.pov.parent, text)) {
      object_variable = GetObject (text)
      if (HasAttribute (object_variable, "look")) {
        if (TypeOf (object_variable, "look") = "string") {
          msg (object_variable.look)
        } else if (TypeOf (object_variable, "look") = "script") {
          invoke (object_variable.look)
        }
      } else if (HasAttribute (object_variable, "description")) {
        if (TypeOf (object_variable, "description") = "string") {
          msg (object_variable.description)
        } else if (TypeOf (object_variable, "description") = "script") {
          invoke (object_variable.description)
        }
      } else {
        msg (StringListItem (response_object.default_response_stringlist_attribute, GetRandomInt (0, ListCount (response_object.default_response_stringlist_attribute) - 1)))
      }
    } else if (HasAttribute (game.pov.parent, response_stringdictionary_attribute)) {
      if (DictionaryContains (game.pov.parent, response_stringdictionary_attribute, text)) {
        msg (StringDictionaryItem (game.pov.parent.response_stringdictionary_attribute, text))
      } else {
        msg (StringListItem (response_object.default_response_stringlist_attribute, GetRandomInt (0, ListCount (response_object.default_response_stringlist_attribute) - 1)))
      }
    } else {
      boolean_variable = true
      foreach (object_placeholder_variable, GetDirectChildren (game.pov.parent)) {
        if (HasAttribute (object_placeholder_variable, response_stringdictionary_attribute)) {
          if (DictionaryContains (object_placeholder_variable, response_stringdictionary_attribute, text)) {
            boolean_variable = false
            msg (StringDictionaryItem (object_placeholder_variable.response_stringdictionary_attribute, text))
          }
        }
      }
      if (boolean_variable) {
        msg (StringListItem (response_object.default_response_stringlist_attribute, GetRandomInt (0, ListCount (response_object.default_response_stringlist_attribute) - 1)))
      }
    }
  </script>
</command>

<object name="response_object">
  <attr name="default_response_stringlist_attribute" type="list">
    <value>YOUR_CREATIVE_DEFAULT_RESPONSE_1</value>
    <value>YOUR_CREATIVE_DEFAULT_RESPONSE_2</value>
    // etc <values>
  </attr>
</object>

// your various Objects (if desired for them) would need a 'response_stringdictionary_attribute' Stringdictionary Attribute. I can try to explain how to set up and how they work and what they do, if you need help on using Dictionary Attributes. The various 'text' inputs would be your 'keys' for the Dictionary Attribute, and then you give them their responses as the 'values' for each of those 'keys'

// I can include code for handling the use of a Scriptdictionary Attribute as well, if interested

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


hmm... that's a strange error... as it seems to be talking about this:

<command name="xxx">
  <script>
    // scripting
  </script>
</command>

which is correct... there shouldn't be an error... (unless this command is over-riding/writing a built-in Command, using 'response' probably wasn't the best idea... as there's probably built-in stuff using 'response'), otehrwise, I've no idea what this error is refering to, hmm....


I've probably done it wrong.

  • I created a new game.
  • Added a new command in Game
  • I put response_command in the Name field
  • I put response #text# in the Command pattern filed
  • Then I put the rest in the script.

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

Support

Forums