verb and attributes

Hello! Im new to Quest and have been making my way through the docs and tutorials. I do not though understand the Verbs are just script attributes section. Specifically this code:

  do (chair, "sit")
}
else {
  msg ("Nothing to sit on here!")
}.

The example I follow in my test game crashes the program. I don't know if its the wording of the doc or something Im not following correctly but I cant seem to get it right. I think its because the code calls back to itself? If someone could show or explain to me what is should look like so if functions properly Id really appreciate it because I am stumped.

doc being referred to: http://docs.textadventures.co.uk/quest/using_verbs.html


Hello!

Welcome to the Quest community!

Also, thanks for linking to what you're working with! That is very helpful!


I think (maybe) this part of the docs was written before Quest had a default sit command, and then some parts of it were updated later (maybe; I'm just guessing).

Anyway, to see why your code is causing Quest to misbehave, we'd really need to see (at least that part) of your code.

...but it might help if I showed you how I would handle this in the current version of Quest.

First, (only if using the desktop version of Quest) I would copy the sit command into my game's main code to override it.

(If using the online Quest editor, you just create a new command named sit_cmd with the pattern sit;sit down, and that would override the default sit command. You can also do it this way in the desktop editor, by the way.)

Then, I would change the script of that "imported" sit command to this (which is very similar to the script in the example to which you are referring, but updated for Quest 5.8 (and overall performance)):

if (chair.parent = game.pov.parent) {
  do (chair, "sit")
}
else {
  msg ("Nothing to sit on here!")
}

Note that there will be an error if there is no existing chair object in your code.

Error running script: Error compiling expression 'chair.parent = game.pov.parent': Unknown object or variable 'chair'


Also, if you were to post your error, we can usually read the error to get closer to what the problems is. :o)


Anyway, then I add my "sit on; sit upon; sit down on; sit down upon" verb to my chair object, and I just put a text response to test things out in this example. My string is This is no time to be sitting around in chairs!

...and I get an error!

Error running script: Object reference not set to an instance of an object.

Oh, no!

This is happening because the line of code do (chair, "sit") expects a script, not a string of text.

If I change my verb on the chair to this script, everything works:

msg ("This is no time to be sitting around in chairs!")

Another solution (the better solution) would be to alter the sit command's script to handle things whether or not the verb on the chair is a string or if it's a script:

if (chair.parent = game.pov.parent) {
  if (TypeOf(chair.sit) = "string") {
    msg (chair.sit)
  }
  else {
    do (chair, "sit")
  }
}
else {
  msg ("Nothing to sit on here!")
}

Now, that works no matter what kind of verb attribute we decide to use (string (meaning a text response) or to run a script).

Here is the example game I used to test things:

<!--Saved by Quest 5.8.7753.35184-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="chair_example">
    <gameid>b74d0d62-f664-4d6f-b1b4-39af84095b0e</gameid>
    <version>1.0</version>
    <firstpublished>2021</firstpublished>
  </game>
  <command name="sit">
    <pattern type="string">^sit$|^sit down$</pattern>
    <script>
      if (chair.parent = game.pov.parent) {
        if (TypeOf(chair.sit) = "string") {
          msg (chair.sit)
        }
        else {
          do (chair, "sit")
        }
      }
      else {
        msg ("Nothing to sit on here!")
      }
    </script>
  </command>
  <object name="room">
    <inherit name="editor_room" />
    <isroom />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="chair">
      <inherit name="editor_object" />
      <sit>This is no time to be sitting around in chairs!</sit>
    </object>
  </object>
</asl>

PS

The example expects the sit attribute on the chair object to be a script because logic dictates that.

If the player can actually sit in the chair, there are most probably object attributes which need to be set to let the game know the player is now sitting in the chair -- because you'd now need to check if the player is sitting in the chair before the player might try taking the chair that the player is in, hence causing the entire game universe to collapse in on itself due to too much recursion (the player carrying an object that the player is also sitting in).

So, minimum effort, you'd need to have a script that moved the player object to the chair object when sitting. Then, you'd need another script on a command with the pattern stand;stand up;get up to move the player object from the chair object to the chair object's parent object when the player is sitting in the chair object -- or to otherwise say the player is not sitting in anything when applicable.

Actually moving the player object to the chair object would probably cause behavior you wouldn't expect, though, unless you already set the chair object up as an object/room. Usually, there would be a flag set up on either the player or the chair (or preferably both) to let the game know when the player is "sitting" in the chair.

This factor alone (actually moving the player to the chair) would cause everything to behave differently than in the example I am currently going by, though. So, ignore that. No moving. We'll just pretend we set chair.being_used to true in the script when the player sits down, and setting it to false when the player stands up or goes somewhere (if possible while sitting).

You'd also want to add a take script to the chair to check whether or not the player is sitting in it before taking it.

Also, you'd want to modify the go command's script to handle whether or not the player gets up out of the chair automatically before going anywhere while seated, or if the player has to manually stand up before going somewhere while seated.


Also also, sorry to get so technical after you said you are new, but you started it by asking about this!

:)


If you have any more questions, please, do not hesitate to ask!

Good luck!


Wow yeah this was very helpful, thanks a lot! I understand what's going on much more now. Taking your suggestion also worked. I cant code myself so some of this is hard to understand or fully grasp when reading the code view. I had the idea that some default code was at play when trying to go by the docs example but I didn't know you could override them in the library elements until now. (Also sorry I'm just now noticing I was missing the first line of that code from the doc.)

Going over your PS trying to make it so you can sit, stand, take (only when standing) the chair and stand from where ever you drop the chair to understand things more. I seem to have it working with adding the being_used attribute if that's what you meant. Made it so that the player can only take the chair if its false and making it true when sat on. Is that what you meant by using that instead of the flags?

As for the go command the only thing I can think of to make it so that you leave the chair when you go to another room was setting the chair.being_used to false.

Again thank you for your help!


I cant code myself so some of this is hard to understand or fully grasp when reading the code view.

I was in the same boat 3 or 4 years ago.

You'll catch on. :o)


Going over your PS trying to make it so you can sit, stand, take (only when standing) the chair and stand from where ever you drop the chair to understand things more.

It seems like you pretty much got a handle on it.

Also, a flag is the same thing as a boolean attribute. So, you did it exactly the same way I'd have done it; you just call it a flag (which is correct; both things mean the same thing).


As for the go command the only thing I can think of to make it so that you leave the chair when you go to another room was setting the chair.being_used to false.

That's a good way to handle it.

The easiest thing would probably be putting an After leaving the room script on the room with the chair to handle that.


If you need any more help, that's what we're here for!

Good luck, and happy gaming!


Sorry, one more thing (for now!)

In the same part of the doc it says you can add multiple verbs that have different meanings, in the verbs and attributes section, to the same object and have one invoke the other! When I add the verbs though it also displays both of them in the game and I'm sure no one would want two verbs being displayed that do the same thing and that that wasn't the docs intention.

I could disable the display for the verbs and only have it display the ones I want but that seems like much more of a roundabout way of doing it. Is this another case of it being for an older version of Quest or am I doing something wrong?


Hello!

Um... I usually disable the links. So, I'm not very knowledgeable concerning this, but I think it's just a little complicated and nothing you're doing incorrectly or anything like that.

Let me find a link that might help. . .

Here we are:
https://docs.textadventures.co.uk/quest/display_verbs.html

This section in particular:
https://docs.textadventures.co.uk/quest/display_verbs.html#coding

If that doesn't help, just let us know. I may not be well-versed in this particular part of Quest, but other people here are. :)


It kindve helps. Its just odd that the doc has you go about this way of using different verbs that mean the same thing to one object when you can just add those different words to the command pattern. Maybe that was for a version before you could have more than one.


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

Support

Forums