Use answer of "get input" as an object name

I am so sorry for what is most likely a very simple answer, but I have been scouring through the forums and tutorials for hours now with no success.

I want to make a small hint system for my game. I noticed two potentials - one in the tutorial pages that deals with hints as objects (which I found quite ingenious), and another in the forums from K.V. using a hint dictionary. Both seemed great, although I was imagining something a bit different.

Since the games I am wanting to make are centered around escape rooms, I wanted the hint system to be similar, where clues are given in relation to the items available. What I want is fairly straightforward - the player types in the command HINT; the game asks what item the player wants a hint on; the player types their response; the game checks to see if the response is, indeed, an object in the game with the "hint" attribute, and if it is, it runs the hint script for that object.

For the life of me, however, I cannot seem to get that last part to work. I know that the player input to the question is saved as the string "result". I know that I can call an item's attribute with "do". I know that the code:

msg ("<b><i>What item would you like a hint on?</i></b/>")
get input {
  do (smallclock, "hint")
}

will activate the "hint" attribute for the item "smallclock" no matter what the user input is. I know that I cannot write:

do (result, "hint")

because that would just look for an object called "result".

I basically just need to know how to call a variable object. I know the answer is staring me right in the face, but I'm too tired to figure it out and I just want to move past this wall because I'm so close to finishing. Thank you for reading!


You could have:

  do (GetObject(result), "hint")

GetObject turns a string object name into an object. But, it will only match the exact object name, not any aliases.

It would really be easier to have the player type "hint clock" or similar. Then you could make the command's pattern hint #object# and Quest will do the hard work of working out which object the player means.

If you really want to make a prompt where the player is expected to type the name of an object, you can either use GetObject (in which case they must type the exact name of the object, case sensitive, and the name rather than the alias), or move a command with the pattern #object# into the room temporarily, so that the next thing the player types is guaranteed to trigger that command.


Thank you very much for your reply! I was trying GetObject, and completely misunderstood that it could only match the exact object name. Thank you for clarifying why it wasn't working, because I was so confused.

I am, indeed, using your verb suggestion as my backup. It works fine, of course. One of the reasons that I wanted to try this with a command, however, was because at some point in time I would like to make a "Hint Button" on an additional panel in the UI. If they hit the "HINT" button, then the command would activate, and the inquiry for what item the player wants a hint on would come up. This would, in my mind, make the experience feel a touch more like an escape room.

However, that being said, you did make me think of a possibility. Would I be able to turn the result of the question in the command HINT into the "object2" variable of the verb? For example, the below code checks if a particular call of the HINT verb can work for a specific item. I feel like it should be somehow possible to reassociate the answer stored in the string "result" to become "object2", just as if the player had typed HINT OBJECT.

if (not IsDefined("object2")) {
  object2 = null
}
switch (TypeOf(object, this.property)) {
  case ("script") {
    if (object2 = null) {
      do (object, this.property)
    }
    else {
      msg (this.multiobjectdefault)
    }
  }
  case ("string") {
    if (object2 = null) {
      msg (GetString(object, this.property))
    }
    else {
      msg (this.multiobjectdefault)
    }
  }
  case ("scriptdictionary") {
    if (object2 <> null) {
      HandleMultiVerb (object, this.property, object2, this.multiobjectdefault)
    }
    else {
      objectlist = ListCombine (ScopeReachableInventory(), ScopeReachableNotHeld())
      excludelist = NewObjectList()
      list add (excludelist, game.pov)
      list add (excludelist, object)
      candidates = ListExclude(RemoveSceneryObjects(objectlist), excludelist)
      if (ListCount(candidates) = 0) {
        msg (this.multiobjectmenuempty)
      }
      else {
        game.pov.multiverb = this.property
        game.pov.multiverbobject = object
        game.pov.multiverbobjectdefault = this.multiobjectdefault
        ShowMenu (this.multiobjectmenu, candidates, true) {
          if (result <> null) {
            HandleMultiVerb (game.pov.multiverbobject, game.pov.multiverb, GetObject(result), game.pov.multiverbobjectdefault)
            game.pov.multiverb = null
            game.pov.multiverbobject = null
            game.pov.multiverbobjectdefault = null
          }
        }
      }
    }
  }
  case ("null") {
    if (this.defaulttext <> null) {
      msg (this.defaulttext)
    }
    else if (this.defaulttemplate <> null) {
      msg (DynamicTemplate(this.defaulttemplate, object))
    }
    else if (this.defaultexpression <> null) {
      params = NewDictionary()
      dictionary add (params, "object", object)
      msg (Eval(this.defaultexpression, params))
    }
    else {
      error ("No verb response defined")
    }
  }
  default {
    error ("No verb response defined")
  }
}

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

Support

Forums