Unknown object or variable 'Attribute'<Solved?>

D4r4dragon
28 Mar 2018, 01:00

I've been trying to make it so a player can compare objects together in a text adventure and was able to get it so a player is able to take an object and with a verb 'compare' to then have a list of items in the room to compare it to. But now I'm getting an error where it can't see selected object's attribute used to compare them and throws the aforementioned error in the title.
I'm not sure if I need to turn the attribute into a variable of some sort, or what. I am using the downloaded version of quest and have practically no grasp or understanding of code.


XanMag
28 Mar 2018, 01:49

IF I understand what you are trying to do... and IF my suggestion is a solution to what I THINK you are trying to do... =)

  1. I would add a compare verb
  2. I then would choose require another object from the drop down menu
  3. Add scripts for what you want to happen when you compare
  4. Go to the verb 'compare' in the tree of stuff to the left (if you are using online.. I'm not sure. I don't mess with the online version.
  5. Near the bottom, find the object separator and add the word 'to'

You are in a comparing verb room.
You can see a cat, a dog and a mouse.
You can go west.

compare cat with dog
This one is a cat and the other is a dog.

compare dog with mouse
This one is a dog, the other is a mouse.

compare mouse to cat
This one is a mouse, the other is a cat.

You can copy-paste this code in a new game if you want.

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Samples">
    <gameid>1ed65924-e092-43d9-8453-071abbbaf387</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <exit alias="east" to="comparing verb room">
      <inherit name="eastdirection" />
    </exit>
  </object>
  <object name="comparing verb room">
    <inherit name="editor_room" />
    <object name="cat">
      <inherit name="editor_object" />
      <look>It's a cat!</look>
      <compare type="scriptdictionary">
        <item key="dog">
          msg ("This one is a cat and the other is a dog.")
        </item>
        <item key="mouse">
          msg ("This one is a cat, the other is a mouse.")
        </item>
      </compare>
    </object>
    <object name="dog">
      <inherit name="editor_object" />
      <look>It's a dog!</look>
      <compare type="scriptdictionary">
        <item key="cat">
          msg ("This one is a dog.  The other a cat.")
        </item>
        <item key="mouse">
          msg ("This one is a dog, the other is a mouse.")
        </item>
      </compare>
    </object>
    <object name="mouse">
      <inherit name="editor_object" />
      <look>It's a mouse!</look>
      <compare type="scriptdictionary">
        <item key="cat">
          msg ("This one is a mouse, the other is a cat.")
        </item>
        <item key="dog">
          msg ("This one is a mouse, the other is a dog.")
        </item>
      </compare>
    </object>
    <exit alias="west" to="room">
      <inherit name="westdirection" />
    </exit>
  </object>
  <verb>
    <property>compare</property>
    <pattern>compare</pattern>
    <defaultexpression>"You can't compare " + object.article + "."</defaultexpression>
    <separator>with; using; to</separator>
  </verb>
</asl>

D4r4dragon
28 Mar 2018, 02:41

Looking at your code, I couldn't understand it, but putting it into quest makes it easier to understand, and its good. But I don't think what I desire.
I'm trying to compare items without typing out what exactly it is.

I am using a verb to start the comparison, but I'm having the system figure out what there is to compare with a For each(GetDirectChildren(player.parent)) loop to find what is in the room. The player then gets the menu for comparing. But because I am trying not to outright say the name of any object, I am trying to use

If GetObject (result).Weight = GetObject (n).Weight 
   Then
      msg ("" + result + " and " + n + " weigh the same.")

But this keeps giving the error "Error running script: Error compiling expression 'GetObject (result).Weight = GetObject (n).Weight': Unknown object or variable 'Weight'."


K.V.
28 Mar 2018, 04:16

I think this function might fix you up:

  <function name="CompareWeightMenu" parameters="o">
    // Set this up because local variables don't work in ShowMenu
    game.temp_this = o
    // Create a new object list
    list = NewObjectList()
    // Add items in the room with weight attributes to the list
    foreach (o, ListExclude(ScopeReachableNotHeld(),o)) {
      if (HasAttribute(o,"weight")) {
        list add (list, o)
      }
    }
    // Display the menu
    ShowMenu ("To which object would you like to compare?", list, true) {
      // Convert the result string to an object
      obj = GetObject(result)
      // See if the first object's weight matches that of the second
      if (game.temp_this.weight = obj.weight) {
        msg ("MATCH")
      }
      else {
        msg ("NO MATCH")
      }
      // Remove the temporary variable
      game.temp_this = null
    }
  </function>

Try pasting this in place of the code in a new game, and see if I'm understanding what you're wanting to do:

``` ```

D4r4dragon
28 Mar 2018, 06:02

I'm not sure if I did it a logical way... But I made a new Replace Function in the menu mode, then went to code view and then pasted your code into it's place, then went back to menu mode and made a rewrite to the verb to function like your function, cause I don't know how to make and use functions...
And it works. I think turning 'result' into an object 'obj', rather then using 'GetObject (result)', fixed my issue cause it works fine in testing. Thank you very much.


K.V.
28 Mar 2018, 06:52

Awesome!

(That's the same way I learned how to do it, by the way.)


D4r4dragon
28 Mar 2018, 07:07

Again thank you, this is going to help me with so many features, and just over all add to my ease of use when adding in new items rather then adding onto the huge logic chains tethered to each object and the likely bug of forgetting to add onto them all.