Simple inventory using lists

 At certain points in the game, the choices available to the player will depend on whether they have acquired or disposed of certain items.  This led me to explore creating a simple inventory system using Ink LISTs.

Ink's LIST is an elegantly peculiar data type that has features of enums and sets found in other languages, and other capabilities.  A LIST declaration both declares a data type defining the possible values of the list and allocates a variable of this type.

LISTs are manipulated using fairly intuitive operators, for example: += to add values, -= to remove values, ? to query if the list contains values.

The Ink official user's guide has excellent explanations of all the cool features of LISTs.

You can add values specified in one list to another list.  LIST values can share names, but if they do, you must specify which LIST originates the value you mean.  


It turns out to be quite possible to confuse yourself if you are not careful, but it is all quite powerful.



I chose to declare all carriable items using a single LIST and then create a series of container variables of this LIST type.


For the most part, I manipulate the LISTs using normal Ink syntax.



 And use a handful of functions to query and remove expendable items.


An example of their use.












Comments

Popular posts from this blog

Lethe 0.4 - Restoring after dying

Lethe 0.2 Release

Welcome! Starting the Lethe Project