Trying to get a function to work

I was trying out the example 'function' in Quest Help file where you have a function for allowing the player to sit on a chair and the result is a message. I tried this but I get an error message telling me that it did not know the Seat variable.

I created a function called SitDown with a parameter called Seat
The script in the function prints the message "You sit down"
I added a chair to the room and in the chair's verbs I added the verb "sit on" and created a script that called the "SitDown" function and added the parameter "Seat"

When I type "sit on chair" I get this error:
Error running script: Error compiling expression 'Seat': Unknown object or variable 'Seat'

I tried added the attribute "Seat" to the chair object attributes and set it to Object. But still no luck.

Where did I go wrong?


When you're calling the functioin, the parameter needs to be an object or variable that exists.

As you've named the parameter Seat, it looks like you're using this parameter to let the function know which object the player is trying to sit on.

So where you call the function, you need to tell Quest which object this is. So it would be something like:

SitDown (chair)

or

SitDown (this)

Then within the function, you can use the variable Seat to refer to the chair. And if you later add a couch or a bed that you can sit on, you can use the same function, just passing a different parameter.


Hi mrangel.
I tried your suggestion of adding SitDown(Seat) but still get an error.
I decided to give you all the code bits in hope you can tell me what to change to get this function to work.

 <verb>
    <property>siton</property>
    <pattern>siton</pattern>
    <defaultexpression>"You can't siton " + object.article + "."</defaultexpression>
  </verb>

 <object name="Chair">
      <inherit name="editor_object" />
      <sit type="script">
        SitDown (Seat)
      </sit>
      <Seat type="object">Chair</Seat>
    </object>


 </function>
  <function name="SitDown" parameters="Seat">
    msg ("You sit on it")
  </function>

I tried your suggestion of adding SitDown(Seat)

I suggested SitDown (this) - you're telling it what to sit on.

  <verb>
    <property>siton</property>
    <pattern>sit on;sit</pattern>
    <defaultexpression>"You can't sit on " + object.article + "."</defaultexpression>
  </verb>

    <object name="Chair">
      <inherit name="editor_object" />
      <siton> type="script">
        SitDown (this)
      </siton>
    </object>

<function name="SitDown" parameters="seat">
  msg ("You sit on "+seat.article+".")
</function>

Hi mrangel.

I modified my code to what you suggested but when i type "sit on the chair" I get the message "You can't sit on it" instead of the message "You sit on it"
Below is my modified code. There is a chair in the room when I type this command.

 <verb>
    <property>siton</property>
    <pattern>sit on</pattern>
    <defaultexpression>"You can't sit on " + object.article + "."</defaultexpression>
  </verb> 


<object name="Chair">
      <inherit name="editor_object" />
      <sit type="script">
        SitDown(this)
      </sit>
      <Seat type="object">Chair</Seat>
    </object>

 <function name="SitDown" parameters="Seat">
    msg ("You sit on "+seat.article+".")
  </function>

I noticed that problem in the previous piece of code you posted; and corrected it in my previous reply.

I've edited my previous post to highlight (in different colours) the names that need to match each other. In this case, the property "siton" (shown in green).

You can change these names to whatever you want, but the ones highlighted in the same colour need to be the same as each other.


Thanks mrangel.

All is working OK now.
I also needed to change 'Seat' to 'seat' as Quest is case sensitive.


Log in to post a reply.

Support

Forums