Hash tables are like ini files, containing a item, in a table, with a value the tables can be freed, created, modified, deleted, and of course loaded, saved to plain text files (txt), or binary.
You can also retrieve your data from your tabels, using identifiers.
So why use hash tables? you might ask. Well hash tables can store a lot more information then ini files, and you more quickly retrieve data from your script.
A little (but pathetic) illusion of a table could be:
Table1
-----------------
Item1 | Value 1
Item2 | Value 2
Item3 | Value 3
Table2
-----------------
Item1 | Value 1
Item2 | Value 2
Item3 | Value 3
Of course, This isn't how it looks, everything is being performed by using commands, and identifiers.
For creating you'r self a new table, you use /hmake -s if you specify the parameter, you will set a limit on your table of items, but you can always store unlimited items, though specifying the parameter, will increase the speed, so this might be something you want to put on, but not something you have to.
Also, The -s trigger is optional, it will display a result of the command you triggered, etc.
* Made hash table 'example' (100)
So if you'r running/making a script, you probably wouldn't wanna have a message like that displayed. Now lets create some tables while we are learning, first of all, we start out with our /hmake command to make table.
first use: /hmake -s mytable
Now mIRC created a table called mytable, and it's empty, so lets add some items, to test. For adding an item you use /hadd - , now our table is called mytable, and lets say we want to add 2 items called arnie and one called khaled, use this:
/hadd mytable arnie the king
/hadd mytable khaled really evil
Now the table 'mytable' contains 2 items, well how can you find that out while running your script? rather simple. By calling this identifier $hget(mytable,0).item you can retrieve the 'amount' of items you have in your table. Calling a certain items value is simply: $hget(table,item), so if you added your hash table as I told you above, you should be able to type now: //echo -a * Table: $hget(mytable,arnie) which will return 'the king', which we set as the 'arnie' value.
Lets make a little tool for when you create your tables. Lets say you wanted to check what items you currently have in a specified table, here's the source (commented with ';'), And this goes to Aliases (Alt+A)
hlist {
; check if you specified a table to list.
if (!$1) { echo -a * syntax: /hlist
}
; check if the table is empty.
if (!$hget($1,0).item) { echo -a * $1 is a empty table }
; okay, everythings fine, lets 'while loop' the items.
else {
; set the %i variable to '1'
%i = 1
; while %i variable is less then amount of items in the specified table.
while (%i <= $hget($1,0).item) {
; Item contains the current item we are getting which is the number, that %i contains.
%Item = $hget($1,%i).item
; Now let's 'extract' the value from the item.
%Value = $hget($1,%Item)
; Display the item/value on the screen.
echo -a * Item: %Item Value: %Value
; Increase %i (%i + 1), and go back to the top at "while"
inc %i
}
; Display amount of items, from which table.
echo -a * Listed $hget($1,0).item Items from $1 Done.
}
}
Now of course I don't expect you to understand this right away, some things might get tricky, and maybe this wasn't the best introduction, but I figured some examples needed to be shown.
Now we seen how we can read items, values, make tables, so how do you delete them? And save/load them?
Deleteing your table is simple, can be done with one with command, /hfree
if you use the -w trigger infront of the table, you'r telling mIRC that it should be free tables as matches. etc. /hfree test*, would delete test1 test2 test3 tables.
Deleting items from your table, is using /hdel - , you can also use the -w wildcard trigger on items, but again its optional.
Saving and Loading
Save your table, by using /hsave , etc. /hsave mytabel c:\table.txt for saving the files in your mirc directory, use $mircdirtable.txt instead of c:\table.txt (instead of having a chaos in your c:\ root directory). If you specify the -b trigger your table will be saved as binary, specifying the -n trigger will only save the values, and not the items. You get the point i'm sure.
Now load tables, by using /hload , will load the specified filename into the specified table, you can also use the -b binary trigger (if you saved your table binary) you have to use this trigger.
There are also other identifiers for tables, etc: $hregex, $hmatch, $hfind. But I won't go into depth with them, for now that is.
Anyways it's been a while since I posted a lesson, so I hope you enjoy, and happy scripting. Please drop a comment to me, Thank you.
? Discuss This Article here.
|