List Library Lite

Overcat
15 Apr 2009, 19:11
I'm building a list library, and am releasing a Lite version for testing. I've used the Lite version (or a variation of it) in my OneRoom competition entry.

Although this library is intended for those who script in a text editor (apart from the QDK), I have hopefully written the documenation in such a manner that even those who are curious about scripting by hand could easily pick up the library as they are learning the in's and out's of ASL.

The library adds a 'list' type to your game file, which allows you to attach lists to any object in your story (provided each list on the object has a unique name). It's a pretty threadbare library as far as functionality goes. You can:

1. create a list or lists on any object
2. add an item to the top or bottom of a list
3. remove an item from a list - either every instance of that item, or only a particular occurrence (ie, only the second time it occurs in a list)
4. remove the first item of a list
5. remove the last item of a list
6. empty a list
7. delete a list from an object
8. see if an item exists in a list
9. remove an item at a particular position in a list
10. count how many items are in a list
11. count how many of a particular item are in a list

The documentation shows you how to iterate through the items in a list on an object. You can also iterate through all the lists on an object.

<<Download the Library and Documentation>>

paul_one
16 Apr 2009, 01:59
I'd suggest including a small test game to show an example of the few main points.

Adding/removing from parts of the list (start/middle/end)
Searching the list
Creating/deleting the list
Multiple lists per object

.. On the subject of searching for multiple instances of an item in the list - can you put it into some sort of for loop?
So you can search the list, get the first instance, do something, search again, get the second instance.

Sorry, I've only had a cursory look over your (seemingly) well written and documented code.

Seems like a good standard way to create and manage lists using properties.

Overcat
16 Apr 2009, 10:24

I'd suggest including a small test game to show an example of the few main points.

Adding/removing from parts of the list (start/middle/end)
Searching the list
Creating/deleting the list
Multiple lists per object



I'm definitely going to include a showcase ASL file for the full version (Land o' Lists). The documentation for the Lite version shows you how to do everything you've mentioned, I think. The Lite version doesn't include a function to return the count of how many times a specific item occurs in a list, however. Although I have that coded already, I didn't include it. Maybe I should - it's kind of basic and handy.

I've also changed the IsInList function to return the position of the first occurence of a searched-for item (rather than just a 1 if it finds the item at all, and a 0 if it doesn't). I thought I had already done that, but it appears I didn't save the changes.

.. On the subject of searching for multiple instances of an item in the list - can you put it into some sort of for loop?
So you can search the list, get the first instance, do something, search again, get the second instance.



You use a for-loop to iterate through the items in a list. For getting the first instance of an item, performing actions with/on it, then getting the next instance and repeating - I do have a scheme for that, but it's not coded yet. Will definitely be included in the full version. The same scheme will also be available to step through all the items in a list without having to use a for-loop. (IE, GetNext, GetPrevious, GetFirst, GetLast, etc.)

Seems like a good standard way to create and manage lists using properties.



I *think* it's pretty good, but then again I'm only one scripter, and may certainly be blinded by my own preferences/experience. With this implementation you can embed lists within lists to create any n-dimensional array you want. The arrays can be jagged or rectangular. Looking at it a bit differently, you can implement a tree structure (of any depth) and use one procedure recursively to discover all the items in the tree. (Recursion was fun to figure out. I had to use a list (a stack) in order to achieve it.)

Overcat
16 Apr 2009, 12:54
I cleaned up the documentation a bit, and added two more functions. The Lite version now allows you to retrieve a count of all the items in a list, or just a count of a particular item. (So if you want to know how many 'apples' are in a list, you can do that.) A new GetByPosition function returns the item listed at a particular position in a list.

In the full version of the list library there are more 'counting' functions. You can count...

* how many objects of a given type are in a list
* how many unique objects are in a list
* how many objects that contain a particular string (in their name) are in a list
* how many objects with a given property or action are in a list
* how many objects with a given property and corresponding value are in a list

I think there are more, but I don't have the library in front of me at the moment.

Overcat
17 Apr 2009, 10:53
I scripted a DeleteList procedure for the full library, and realized that deleting a list from an object should be part of the basic functionality. So it's been added to List Library Lite as of this morning.