MODULE: sHash and sList ( strings as hashtables, strings as lists )

Started by QCPolmer, Wed 26/04/2017 07:14:58

Previous topic - Next topic

QCPolmer


sHash




sHash is a simple module that allows a string to act like a dictionary.

It works like this:
Code: ags

someString = sHashSet( someString , "key1", "subject"); // adds key ''key1" to string
sHashGet( someString , "key1"); // gets ''subject"
someString = sHashRemove( someString , "key1"); // Removes "key1"


This can take strings, ints, and floats ( sHashSetFloat, sHashSetInt, etc. )

Also, here is another, similar script:

sList




This is similar to the above, but it allows strings to act like lists.

Here is how to use it:

Code: ags

someString = sListInsertItem( someString, "ListName", "Text To Add", 0); // adds Text To Add
sListGetItem( someString, "ListName", 0); // fetches "Text To Add"
someString = sListRemoveItems( someString, "ListName", 0, 1); // removes  list item 0


and, best of all, the sList can be shuffled with a single function.

someString = sListShuffle( someString, "ListName");



These two scripts work together fairly well ( they can be nested ).

The one exception is if a key name or list name is inside a sList or sHash with the same key or listname.
In those cases, it starts botching up.

EG:
Code: ags
someString = sHashSet( someString , "key1", "subject"); // adds key "key1" to string
someOtherString = sHashSet( someOtherString , "key1", someString ); // getting "key1" will be a problem



A list of all functions can be found on the github page:
https://github.com/QCPolmer/AdventureGameStudio_sHash

Both scripts are under MIT license.

Enjoy!

( written in AGS 3.3.0 )

Monsieur OUXX

 


SMF spam blocked by CleanTalk