Object Attribute Reference Issue

Hi there,

This is probably an easy fix for people who know more about what they are doing, but I've spent a couple of hours messing around with stuff and it seems to be this line of code that's messing everything up. Are you not allowed to call an attribute on top of the ObjectListItem function?

ObjectListItem(list1,total).defloc

  • list1 is a list of objects
  • total is just a counter for the number of items in the list
  • defloc (default location) is an attribute that both of the objects listed below have and of an object type

list 1 shows this when displayed in-game:
List: Object: Intro Dude; Object: man01;

The error given is this:
Error running script: Error compiling expression 'ObjectListItem(list1,total).defloc': Unknown object or variable 'defloc'

Any help would be greatly appreciated because after trying to look up documentation I'm just kind of trying random syntax things at this point.


I don't think you can use an attribute on an expression like that. You might need to make it GetAttribute (ObjectListItem(list1, total), "defloc") instead.

I could be wrong, haven't tried it myself. And most programming languages allow you to do that, so it might be worth trying.

But I do notice:

  • total is just a counter for the number of items in the list

If it's the number of items in the list, then your ObjectListItem will be returning null, which I believe would give the same error.
The list you displayed there has 2 items. Are you sure that the corresponding value of total is 0 or 1?


quest (Edit: I think, but could be wrong) doesn't have syntax for doing 'FUNCTION.XXX', instead you do this:

VARIABLE = GetAttribute (ObjectListItem (LIST, INDEX_NUMBER), "NAME_OF_ATTRIBUTE")

or broken down into multiple code lines:

OBJECT_VARIABLE = ObjectListItem (LIST, INDEX_NUMBER)

VARIABLE = GetAttribute (OBJECT_VARIABLE, "NAME_OF_ATTRIBUTE")


so, for your code (assuming everything is otherwise correct about it), an example:

create ("example_object")
example_object.example_attribute = GetAttribute (ObjectListItem (list1, total), "defloc")

// general testing of a "normal" attribute (string/integer):
// msg (example_object.example_attribute)

// or, if I understand correctly that 'defloc' is an Object (reference/pointer) Attribute:
// msg (example_object.example_attribute) // this would display the Object as a clickable button/hyperlink (I think)
// msg (example_object.example_attribute.name) // this would just display the 'name' (ID) of the Object
// or, if you want to move the Player Object to that location (to/contained-within that Object):
// game.pov.parent = example_object.example_attribute


some useful links:

https://docs.textadventures.co.uk/quest/elements/

https://docs.textadventures.co.uk/quest/elements/object.html

https://docs.textadventures.co.uk/quest/types/ (Data Types)

https://docs.textadventures.co.uk/quest/null.html

https://docs.textadventures.co.uk/quest/scripts/

https://docs.textadventures.co.uk/quest/functions/ (categorical order)
https://docs.textadventures.co.uk/quest/functions/index_allfunctions.html (alphabetical order)

https://docs.textadventures.co.uk/quest/functions/objectlistitem.html

https://docs.textadventures.co.uk/quest/functions/getattribute.html

https://docs.textadventures.co.uk/quest/using_lists.html
https://docs.textadventures.co.uk/quest/using_dictionaries.html


Edit:

going off of mrangel's post, you can do something like this, example of using randomization:

create ("example_object")

create ("forest_object")

create ("desert_object")

example_object.example_objectlist_Attribute = NewObjectList ()
list add (example_object.example_objectlist_Attribute, forest_object)
list add (example_object.example_objectlist_Attribute, desert_object)

// hopefully you already understand lists/arrays usage, if not and/or if can't follow/understand the single line of code below, let me know, and I'll break it down into multiple code lines and explain it too (but right now, too tired and lazy to do so, lol)

example_object.example_attribute = GetAttribute (ObjectListItem (example_object.example_objectlist_Attribute, GetRandomInt (0, ListCount (example_object.example_objectlist_Attribute) - 1)), "defloc")

game.pov.parent = example_object.example_attribute
// the Player Object will be moved into either:
// forest_object
// or
// desert_object

Thanks to you both so much, the code suggestion worked like a charm! I was not aware of the Get Attribute function like below. I think it'll be really useful for what I'm doing right now and solve a lot of problems.

GetAttribute (ObjectListItem(list1, total), "defloc")

Basically, my thought process was that ObjectListItem(list1,total) would return an object, so it would translate to Intro Dude.defloc to get the attribute. I wasn't thinking about it as a function, because I rarely code and am not very good at it.


it's a Function that indeed does return an Object Reference/Pointer, you're correct about this

but I don't think (again could be wrong) that quest is able to put/handle the returned value into such an expression (NNN.XXX) that it would then be able to act upon further


Quest's lexer, sadly, is kind of nasty. It has to be, to cope with variable names that can have spaces and punctuation in.

I've not tried using array notification like this. I'm wondering if list1[total].defloc would work. As far as I understand it, this notation for a list item is implemented as by a strange bodge that doesn't work like any other IASL construct; so there's a chance it might work.

GetAttribute, its more specific variants GetInt, GetString, GetBoolean, etc, and the corresponding function set, are mostly useful when you don't always want to work with the same attribute (like when you want to loop over a character's stats, for example), because it uses a string for the attribute name, and that string can come from a variable. But in situations like this, it provides a little bit of syntactic sugar.


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

Support

Forums