From WikiChip
/hinc Command - mIRC
< mirc‎ | commands
Revision as of 20:01, 16 June 2018 by Maroonbells (talk | contribs)

The /hinc command increases the value of a hashtable item by [num]. If the optional number value is not specified, the default value is 1.0. It uses the same syntax as /hadd except it does not support the -b switch recognizing item values as being binary variables.

Synopsis

/hinc [-m[N]szuNk] <table> <item> [num] 

Switches

  • -m[N] - Creates the hash table if it does not exist, optionally setting the number of buckets to N. (Valid N 1-10000)
  • -s - Displays the assignment information
  • -z - After setting the data's value, decreases the value by 1.0 each second; unsets to prevent the data value being zero or negative
  • -uN - Removes the hashtable item/value after N seconds
  • -k - Keep the existing unset delay while altering the existing data value

Note: If hashtable item has non.zero $hget(table,item).unset property due to being created or modified by -uN or -z switch when created or modified with /hinc /hdec or /hadd, then /hsave will not save that item to disk without the /hsave -u switch.

Parameters

  • <table> - The handle name of the table containing the 'item'
  • <item> - The item name associated with the data value
  • [num] - The optional value by which to increase the data value. If not present, increases by 1.0

Example

Example 1:

alias example {
  ;create the table
  hmake -s example
 
  ;add a few items
  hadd example item1 4
  hadd example item2 7
  hadd example item3 9
 
  ; print the items
  echo -a item1 = $hget(example, item1)
  echo -a item2 = $hget(example, item2)
  echo -a item3 = $hget(example, item3)
 
  ; increase the values
  hinc example item1 5
  hinc example item2 12
  hinc example item3 1
  
  echo -e -
 
  ; print the items
  echo -a item1 = $hget(example, item1)
  echo -a item2 = $hget(example, item2)
  echo -a item3 = $hget(example, item3)
 
  ;cleanup
  hfree -s example
}

A counter example:

alias countup {
  ;adds the item up with a value of 0 to the table count
  hadd -m count up 0
  echo -a $hget(count,up) $+ !
  :repeat
  ;checks if the value of down returns true
  if ($hget(count,up) < 9) {
    ;increases down by 1
    hinc count up
    ;echos the current count
    echo -a $hget(count,up) $+ !
    ;repeats
    goto repeat
  }
  ;if the previous if statement returns false it carries on with this.
  else echo -a 10, done!
  hfree -s count
}
//hfree -sw test | hinc -sm test foo 5 | echo -a item foo has value $hget(test,foo)
Result: 5
* If the item does not exist, /hinc behaves as if the item exists with a value of zero.
 
//hfree -sw test | var %a 0 | hadd -sm test foo 5 | hinc test foo %a | echo -a item foo has value $hget(test,foo)
Result: 5
//hfree -sw test | var %a   | hadd -sm test foo 5 | hinc test foo %a | echo -a item foo has value $hget(test,foo)
Result: 6
* If variable used to increment the item is $null the increment is the default 1.
 
//hfree -sw test | hadd -sm50 test foo 9.123456789 | echo -a item foo has value $hget(test,foo) | hinc -s test foo 2 | echo -a item foo has value $hget(test,foo)
* While a hash table value can be created having more than 6 decimals, the result of /hinc is rounded to nearest 6 decimals, the same result as if $calc(old_value + increment_value). If the [num] parameter is incorrectly set to be non-numeric, the item is unset 1 second later because $calc(string - 1) is zero.
 
//hfree -sw test | hadd -sm50 test foo 30 | echo -a item foo has value $hget(test,foo) | hinc -sz test foo 50 | echo -a item foo has value $hget(test,foo) and will unset in $hget(test,foo).unset secs
* After the value has been incremented, -z begins with the incremented value then decreases it once per second, but also gives the item the characteristic as if -u2147483647 were also used. (2^31-1)
 
//hfree -sw test | hadd -sm50 test foo 30 | echo -a item foo has value $hget(test,foo) | hinc -szu30 test foo 50 | echo -a item foo has value $hget(test,foo) and will unset in $hget(test,foo).unset secs
* Same as above, except -u30 modifies the future unset time to be 30 seconds instead of 2147483647.
 
//hfree -sw test | hadd -sm50u30 test foo 30 | echo -a item foo has value $hget(test,foo) | hinc -k test foo 50 | echo -a item foo has value $hget(test,foo) and will unset in $hget(test,foo).unset secs
* -k preserves the existing future unset time of the hashtable item, and has no effect if the item hadn't been created using the -uN or -z switches.
 
* Note: Any data value created or modified using the -z or -uN switch has the characteristic of being unset in the future, and /hsave will not save that item/data pair to disk unless the /hsave -u switch is used.
 
//hfree -sw test | hinc -smzu10 test foo 30.4 | .timer 11 1 echo 4 -a value $!hget(test,foo) vs .unset  $!hget(test,foo).unset
//hfree -sw test | hinc -smzu10 test foo 5.44 | .timer 11 1 echo 4 -a value $!hget(test,foo) vs .unset  $!hget(test,foo).unset
* When item is created using both -z and -uN, the variable is unset to prevent the first of either .unset seconds reaching zero or the value decrements to be zero or negative.

Compatibility

Added: mIRC v6.0
Added on: 03 Feb 2002
Note: Unless otherwise stated, this was the date of original functionality.
Further enhancements may have been made in later versions.

See also