From WikiChip
Difference between revisions of "mirc/commands/hinc"
< mirc‎ | commands

m (Bot: de-linking old mIRC menu)
Line 1: Line 1:
 
{{mirc title|/hinc Command}}
 
{{mirc title|/hinc Command}}
The '''/hinc command''' increases the value of a key by [num]. If the value is not specified, the default value is 1.0.
+
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 ==
 
== Synopsis ==
  /hinc [-mszu#] <nowiki><table></nowiki> <key> [num]  
+
  /hinc [-m[N]szuNk] <nowiki><table></nowiki> <item> [num]  
/hinc -b[cmszu#] <nowiki><table></nowiki> <key> <&bvar>
 
 
 
 
== Switches ==
 
== Switches ==
* '''-m''' - Creates the hash table if it does not exist  
+
* '''-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  
+
* '''-s''' - Displays the assignment information
* '''-b''' - Treats the value as a binary variable
+
* '''-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
* '''-c''' - Truncates the &bvar at the first null value  
+
* '''-uN''' - Removes the hashtable item/value after N seconds
* '''-z''' - Decreases the value by 1.0 every second; stops at zero
+
* '''-k''' - Keep the existing unset delay while altering the existing data value
* '''-u#''' - Removes the key/value after # seconds
+
'''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 ==
 
== Parameters ==
* '''<nowiki><table></nowiki>''' - The handle name of the table to operate on
+
* '''<nowiki><table></nowiki>''' - The handle name of the table containing the 'item'
* '''<key>''' - The key associated with the value  
+
* '''<item>''' - The item name associated with the data value
* '''[num]''' - The value to decrease the value by
+
* '''[num]''' - The optional value by which to increase the data value. If not present, increases by 1.0
* '''<&bvar>''' - The binary variable value to decrease the value by
 
 
 
 
== Example ==
 
== Example ==
 
Example 1:
 
Example 1:
Line 73: Line 67:
 
}</syntaxhighlight>
 
}</syntaxhighlight>
  
 +
<source lang="mIRC">
 +
//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.
 +
</source>
 
== Compatibility ==
 
== Compatibility ==
 
{{mIRC compatibility|6.0}}
 
{{mIRC compatibility|6.0}}
 
 
== See also ==
 
== See also ==
* [[List of commands - mIRC|List of commands]]
+
{{collist
* [[List of identifiers - mIRC|List of identifiers]]
+
|count = 3
* {{mIRC|$hget}}
+
|style = width: 60%; display: inherit;
* {{mIRC|$hfind}}
+
|
* {{mIRC|/hadd}}
+
* {{mIRC|/hmake}}
* {{mIRC|/hdec}}
 
* {{mIRC|/hdel}}
 
 
* {{mIRC|/hfree}}
 
* {{mIRC|/hfree}}
 
* {{mIRC|/hload}}
 
* {{mIRC|/hload}}
* {{mIRC|/hmake}}
 
 
* {{mIRC|/hsave}}
 
* {{mIRC|/hsave}}
{{mIRC command list}}
+
* {{mIRC|/hadd}}
 
+
* {{mIRC|/hdel}}
[[Category:mIRC commands|hinc command - mIRC]]
+
* {{mIRC|/hdec}}
 +
* {{mIRC|Hash Tables}}
 +
* {{mIRC|$hget}}
 +
* {{mIRC|$hfind}}
 +
}}

Revision as of 20:01, 16 June 2018

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