Difference between revisions of "Hadd"

From Scriptwiki
Jump to: navigation, search
(added sentence about hinc / hdec)
(added -s switch.)
Line 1: Line 1:
 
Adds an item to an existing hash table.
 
Adds an item to an existing hash table.
 
  /hadd -smbczuN <name> <item> [data | &binvar]
 
  /hadd -smbczuN <name> <item> [data | &binvar]
 +
 +
Using the -s switch makes the command disply the result (e.g. ''* Added item 'Dana' to hash table 'users''')
  
 
The -m switch makes /hadd create the hash table if it doesn't already exist.
 
The -m switch makes /hadd create the hash table if it doesn't already exist.

Revision as of 19:52, 20 November 2005

Adds an item to an existing hash table.

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

Using the -s switch makes the command disply the result (e.g. * Added item 'Dana' to hash table 'users')

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.

The /hinc and /hdec commands use the same parameters as /hadd and increase or decrease the number value of an item.

When used with /hinc or /hdec, the -c switch increases or decreases the value once per second.

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.