Check inventory of an item

In my game, the player could have item: club, item:club1 or item:club2...
How would I check to see if the player has one of these clubs???
I found Got(item)
but does that check for the item.name or item.alias??


Got checks for a particular item.

If you want to filter by alias you could use something like:

if (ListCount (FilterByAttribute (ScopeInventory(), "alias", "club")) > 0) {

(Though it's probably better to use prototype if you want to search for clones of a particular item)


Gota love the long structure of Quest commands!!!
so, to break this down:
if (ListCount = the count of the select item
(FilterByAttribute = look at "alias" for "club"
(ScopeInventory(), = and this is the list of what's in the player's inventory.
"alias", "club")) > 0) {
Right?
OK, so how does prototype work?
I've got the downloaded Quest docs, but it's not listed.


I think you got it.

I think it's easiest to understand long commands by working from the inside out. Like, you look at the innermost set of parens/brackets, work out what that does, and then look at what the function around it does with it.

So you could break that command down as:

  • ScopeInventory() → contents of the player's inventory
  • FilterByAttribute (contents of the player's inventory, "alias", "club") → items in the inventory whose "alias" attribute has the value "club" → list of clubs in the inventory
  • ListCount (list of clubs in the inventory) → number of clubs in the inventory
  • if (number of clubs in the inventory> 0) { → if player has more than zero clubs

OK, so how does prototype work?

prototype is a recent addition, I think. When I started using Quest I added it to all my games myself using a 3-line start script, but it's now part of the core.
The CloneObject() function gives the clone an attribute prototype which contains a reference to the original object. So instead of FilterByAttribute (some list, "alias", "club") you can make your code look more like FilterByAttribute (some list, "prototype", club).

Comparing the object reference and the alias are pretty similar in efficiency. But there's a few reasons the alias of an object might change. For example, in my demo game for the crafting system I had "boring book", "battered book", "old bible", "paperback novel", etc… with aliases built out of a random list of adjectives and nouns. If you might at some point add any feature that changes the name of an object, it's easier to use the prototype to determine what kind of thing an object is.

Hope that makes some kind of sense. I'm kind of spaced out, having burned myself out over the last 2 days getting a book published.


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

Support

Forums