Hadd

From Scriptwiki
Revision as of 20:24, 20 November 2005 by Doomie (talk | contribs) (edited minor thing)

Jump to: navigation, search

Adds an item to an existing hash table.

/hadd -smbczuN <name> <item> [data | &binvar]

The -m switch makes /hadd create the hash table if it doesn't already exist.

The -uN switch unsets the item after N seconds.

The -b indicates that you're adding a &binvar item to the hash table.

The -c switch chops the &binvar up to the first null value and treats it as plain text.

The -z switch decreases hash item once per second until it reaches zero and then unsets it.

Note that if the item you're adding already exists, the old item is replaced.

Example

hadd -m users Dana $address(Dana,5)

This example will, if it doesn't already exist, make a new hashtable called "users" and add Dana as item and Dana's address as value to it.

The next, more complex example, will add all users, who are currently in #help.script and their addresses to a hashtable called users.

; make a new hashtable called users
hmake users 
var %i = 1
; begin to loop through all users in #help.script
while (%i <= $nick(#help.script,0)) {
 ; actually add it to the hashtable
 hadd users $nick(#help.script,%i) $address($nick(#help.script,%i),5)
 ; increase looping-variable
 inc %i
}

Be sure that your IAL is up-to-date, if not, execute /who #help.script before.