Hdec » History » Version 1
Per Amundsen, 02/11/2014 03:47 PM
1 | 1 | Per Amundsen | _Added in 1.9.0_ |
---|---|---|---|
2 | |||
3 | */hdec -bcmsuNz <name> <item> [num | &binvar]* |
||
4 | |||
5 | Decreases the value of the item by 'num'. |
||
6 | |||
7 | *Switches* |
||
8 | |||
9 | -b - Indicates &binvar is set. |
||
10 | -c - Chop the &binvar to first null byte. |
||
11 | -m - Creates the table if it does not exist. |
||
12 | -s - Displays the result. |
||
13 | -uN - Unset the the item after N seconds. |
||
14 | -z - Decreases the item once per second until it reaches zero and then unsets it. |
||
15 | |||
16 | *Parameters* |
||
17 | |||
18 | <name> - The hashtable where the item resides. |
||
19 | <item> - The hashtable item to decrease. |
||
20 | [num | &binvar] - The number or &binvar to decrease by. |
||
21 | |||
22 | *Example* |
||
23 | |||
24 | alias countdown { |
||
25 | ;Adds the item down with a value of 10 to the table count. |
||
26 | hadd -m count down 10 |
||
27 | |||
28 | echo -a $hget(count,down) $+ ! |
||
29 | :repeat |
||
30 | |||
31 | ;Checks if the value of down returns true. |
||
32 | if ($hget(count,down) > 1) { |
||
33 | ;decreases down by 1 |
||
34 | hdec count down |
||
35 | ;echos the current count |
||
36 | echo -a $hget(count,down) $+ ! |
||
37 | ;repeats |
||
38 | goto repeat |
||
39 | } |
||
40 | ;If the previous if statement returns false it carries on with this. |
||
41 | else echo -a 0, Hurray! |
||
42 | hfree -s count |
||
43 | } |