|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
What am i missing here? the hash table have the words stored in it, i can list them to a dialog, but when i trying to remove or add a word it don't notice the word is in the list. nether on add or remove, it add the word over and over again, and when i trying to remove it, then i get that the word don't exist, so what am i missing here? the %var store the word i want to remove, tested to write in the word in the code, still no luck with it. loadbadword loads the words to the dialog, and as i wrote before it show all the words as it show, so nothing wrong there. and i can echo the words to me: moo blaa test and i trying to remove "moo", nothing, and i tested all the word's with the same result..
on *:start:{
if (!$hget(badword)) { hmake badword }
if ($exists(badword.hsh)) { hload badword badword.hsh }
}
alias add.bword {
if ($hget(badword,%badword)) { dialog -t badword The badword $+($chr(34),%badword,$chr(34)) already exists in the list. }
if (!$hget(badword,%badword)) { hadd badword %badword | dialog -t badword The badword $+($chr(34),%badword,$chr(34)) added succesfully. | loadbadword }
}
alias del.bword {
if (!$hget(badword,%rbadword)) { dialog -t badword The badword $+($chr(34),%rbadword,$chr(34)) does not exist in the list. }
if ($hget(badword,%rbadword)) { hdel badword %rbadword | dialog -t badword Badword $+($chr(34),%rbadword,$chr(34)) removed succesfully. | loadbadword }
}
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
if you "/hadd table %badword" (without data), $hget(table,%badword) returns nothing (because it would return the data for item %badword). Check for $hget(table,%badword).item instead
|
|
|
|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
grr, hate it when i miss something like that maybe i sit to long and don't see the "small" errors, when added .item it worked as a charm.. thnx for your help.
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
Joined: Jan 2007
Posts: 1,156
Hoopy frood
|
Hoopy frood
Joined: Jan 2007
Posts: 1,156 |
When you add your entry to the hash table you dont give it any data. hadd badword %badword So when you check for $hget(badword,%badword) the result is $null or $false because there is no data. This is why when you try to remove it with your alias the result is .. if (!$hget(badword,%rbadword)) { dialog -t badword The badword $+($chr(34),%rbadword,$chr(34)) does not exist in the list. } edit: lol, looks like I took too long writing that lol.
Last edited by DJ_Sol; 15/11/08 11:46 PM.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
Yepp it's the smallest things that may cause the most despair And the helpfile isn't explicit about this: "$hget(name/N, N).item" - No word about $hget(name/N, item/N).item
|
|
|
|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
uhum, ok, learn something new every day and your right, i have been reading it over and over again, and couldn't figure out the problem. ;------ edit I don't get it, now i can add 1 word, then if i try add 1 more i get that the word already in the hash table, but it's not. and if i remove the added word, then i can add 1 new and after that the same result, so what's wrong with the code? and yes, the %badword get the new value so it's nothing like that.
alias add.bword {
if ($hget(badword,%badword).item) { dialog -t badword The badword $+($chr(34),%badword,$chr(34)) already exists in the list. }
if (!$hget(badword,%badword).item) { hadd badword %badword | dialog -t badword The badword $+($chr(34),%badword,$chr(34)) added succesfully. | loadbadword }
}
Last edited by sparta; 16/11/08 12:18 AM.
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
You aren't using the full line for the /hadd command /hadd <table> <item> <data> Usage /add.bword <badword1> <badword2>,<badword3>,<badword4> For remote usage: on *:text:!add.bword*:*:{
add.bword $2-
} alias add.bword {
var %bad.words = $replace($strip($1-),$chr(44),$chr(32)), %a = 1, %b = $numtok(%bad.words,32)
while %a <= %b {
var %badword = $gettok(%bad.words,%a,32)
if $hget(badword,%badword) {
dialog -t badword The badword $qt(%badword) already exists in the list.
}
else {
.hadd -m badword %badword $true
dialog -t badword The badword $qt(%badword) added successfully
}
inc %a
}
}
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
RusselB is right - I should have tested it with more than 1 item $hget(table,foobar).item = $hget(table,0).item Use the "data" part (added by? date added?), or add at least a "dummy" data value and refer to if $hget(badword,%badword) like in your initial script ... or (if you don't assing a data value), use if $hfind(badword,%badword)
Last edited by Horstl; 16/11/08 01:35 AM.
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
Actually, $hget(table,0).item will return the number of items in the table. $hget(name/N, N).item This allows you to reference the table as an index from 0 to N, in order to look up the Nth item in the table. If N is zero, returns the total number of items in the table. You can also reference the Nth data value directly with $hget().data. Note: This method is provided as a convenience, it is not an efficient way to use the hash table.
|
|
|
|
Joined: Nov 2006
Posts: 1,559
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,559 |
That's right, and $hget(table,abcd).item is returning the same value (total number of items), not the N of the item abcd if item abcd exists (which I assumed misleadingly because I tested only a single item in a test table).
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
It appears that there isn't an option to return the N portion of $hget(table,N)
|
|
|
|
Joined: Jan 2007
Posts: 1,156
Hoopy frood
|
Hoopy frood
Joined: Jan 2007
Posts: 1,156 |
What about $hfind ...
$hfind(name/N, text, N, M)
Searches table for the Nth item name which matches text. Returns item name.
|
|
|
|
Joined: Oct 2007
Posts: 214
Fjord artisan
|
Fjord artisan
Joined: Oct 2007
Posts: 214 |
Hello, Something I made a while back ago. This one uses the hfind like DJ Sol had mentioned
;==================================================================================================================================
; PROFANITY PROTECTION
;==================================================================================================================================
dialog pfp {
title "Profanity Protection"
size -1 -1 118 126
option dbu
combo 1, 6 9 70 97, sort size vsbar
button "Add", 2, 80 21 32 11, default flat
button "Delete", 3, 80 33 32 11, flat
box "Profanity Protection", 5, 1 0 116 109
button "Delete All", 7, 80 45 32 11, flat
button "Import", 8, 80 69 32 11, flat
button "Export", 9, 80 81 32 11, flat
button "Enable", 11, 80 93 32 11, flat
button "OK", 4, 26 112 32 11, flat ok
button "Cancel", 6, 62 112 32 11, flat cancel
button "Refresh", 10, 80 9 32 11, flat
button "Search", 12, 80 57 32 11, flat
}
#pfp off
on *:EXIT:{ if ($hget(badword)) { hsave badword $+($scriptdir,badword.hsh) } }
on *:DISCONNECT:{ if ($hget(badword)) { hsave badword $+($scriptdir,badword.hsh) } }
on *:TEXT:*:#: {
if ($nick !isop #) && ($hfind(badword,*,0,w) > 0) {
var %i = $hfind(badword,*,0,w) | while (%i) {
if ($hfind(badword,*,%i,w) isin $1-) {
hinc -m Cuss $nick 1 | var %w = $+($mid($hfind(badword,*,%i,w),1,1),$str($chr(42),$calc($len($hfind(badword,*,%i,w)) - 1)))
if ($hget(Cuss,$nick) == 1) { msg # $nick $+ , this is your $ord($hget(Cuss,$nick)) first warining for using profanity! Please refrain from using the word: %w Thank you. }
elseif ($hget(Cuss,$nick) == 2) { msg # $nick $+ , Please consider this is your $ord($hget(Cuss,$nick)) warning for using profanity. A repeat violation will result in you being removed from this chatroom following a 1 hour ban. }
elseif ($hget(Cuss,$nick) >= 3) { kick # $nick Banned: For the using the word %w This was your $ord($hget(Cuss,$nick)) offense (Access ban set for 1 hour) | hfree Cuss }
}
dec %i
}
}
}
#pfp end
; -- ALIASES
alias pfp { dialog -m pfp pfp }
alias rem.word {
var %f = $did($1,$2).lines
while (%f >= 1) {
if ($gettok($did($1,$2,%f),1,32) == $3) return %f
dec %f
}
else return 0
}
alias ref_words {
did -r $1 1 | var %i = 1
while (%i <= $hfind(badword,*,0,w)) {
did -a $1 1 $hfind(badword,*,%i,w)
inc %i
}
hsave badword $+($scriptdir,badword.hsh)
}
on *:dialog:pfp:init:*: {
if (!$hget(badword)) { hmake badword }
if ($exists($+($scriptdir,badword.hsh))) { hload badword $scriptdir $+ badword.hsh }
; -- Load all profane words upon initiallization
if ($group(#pfp) == on) { did -ra $dname 11 Disable }
else { did -ra $dname 11 Enable }
if ($hfind(badword,*,0,w) > 0) { var %i = 1 | while (%i <= $hfind(badword,*,0,w)) { did -a $dname 1 $hfind(badword,*,%i,w) | inc %i } }
}
; -- Add Profane Word ID: 2
; -- Also checks to see that there is no duplication of an entry.
on *:dialog:pfp:sclick:2: {
var %w = $did($dname,1)
if (!$hget(badword,%w)) { hadd badword %w | did -a $dname 1 %w | $ref_words($dname) }
}
; -- Delete a profane word ID: 3
; -- Also checks to see that the word is present before deletion.
on *:dialog:pfp:sclick:3: {
var %w = $did($dname,1).seltext, %l = $did($dname,1).sel
echo -a * %w Deleted! | hdel badword %w | did -d $dname 1 %l | $ref_words($dname)
}
; -- Delete All ID: 7
on *:dialog:pfp:sclick:7: {
if ($hget(badword)) { hfree badword }
did -r $dname 1 | hmake badword | hsave badword badword.hsh | $ref_words($dname)
}
; -- Import Feature ID: 8
on *:dialog:pfp:sclick:8: {
hload badword $sfile($scriptdir $+ badword.hsh,Select a file to import,OK) | $ref_words($dname)
}
; -- Export Feature ID: 9
on *:dialog:pfp:sclick:9: {
hsave badword $sfile($scriptdir $+ badword.hsh,Export List,Save)
}
; -- Refresh Profanity Word List ID: 10
on *:dialog:pfp:sclick:10: { $ref_words($dname) }
; -- Enable/Disable Feature ID: 11
on *:dialog:pfp:sclick:11: {
if ($did(11) == Enable) { .enable #pfp | did -ra $dname 11 Disable }
else { .disable #pfp | did -ra $dname 11 Enable }
}
; -- Search Feature ID: 12
on *:dialog:pfp:sclick:12: {
var %w = $$?="Enter a keyword to search for:"
did -c $dname 1 $didwm($dname,1,%w)
}
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
As you stated, $hfind returns the item name, not the corresponding numeric. Eg: /hadd -m Name temp temp
/hadd -m Name test2 test2
/hadd -m Name text text
//echo -a $hget(Name,).item -> returns 3
//echo -a $hfind(Name,text,0) -> returns 1
//echo -a $hget(Name,1) -> returns temp
//echo -a $hfind(Name,text,1) -> returns text $hget(Name,text).N -> would return 3 (if this function existed) Personally I don't see a real use for a function like that, so I'm not going to put it as a Feature suggestion.
Last edited by RusselB; 16/11/08 04:34 PM.
|
|
|
|
Joined: Jul 2006
Posts: 4,180
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,180 |
$hget(Name,text).N -> would return 3 (if it existed) This is wrong, when using hash table, you should not take care about the N position of an item in the table, that's not how hash table should be used. And $hget(table,1).item always returns the last added item, so $hget(Name,text).N would return 1. If you're (the OP) adding an item with no data, use $hfind as said by Horstl
Last edited by Wims; 16/11/08 04:22 PM.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
I used bad phraseology in the condition in my earlier post regarding $hget(table,item).N and didn't realize it until after your post. I have edited my post to make what I was talking about clearer.
|
|
|
|
Joined: Jul 2006
Posts: 4,180
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,180 |
Lol, even if it's more clearer now, I already understood, it's just that as i said $hget(table,1).item always returns the last added item, so $hget(Name,text).N would return 1 in your exemple.
And while i'm here, in your exemple, $hget(Name,).item return $null and with $hfind(Name,text,0), you're searching for an exact item match, so it will always be 1 and again $hget(Name,1) is $null.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Aug 2004
Posts: 7,252
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,252 |
As it currently works, yes, $hget(Name,text).N would return 1 in your exemple. , however, I think you partially misunderstood what I was trying to refer to. $hget(table,N).item returns the item name What I was, somewhat, suggesting, is something like $hget(table,item).N where N (as used in $hget(table,N)) is returned.
|
|
|
|
Joined: Jul 2006
Posts: 4,180
Hoopy frood
|
Hoopy frood
Joined: Jul 2006
Posts: 4,180 |
I perfectly understood what you was talking about i'm just saying when using hash table, know the N position ($hget(table,n).item) in the table is useless.
#mircscripting @ irc.swiftirc.net == the best mIRC help channel
|
|
|
|
Joined: Feb 2003
Posts: 3,432
Hoopy frood
|
OP
Hoopy frood
Joined: Feb 2003
Posts: 3,432 |
Replying to no one, just have a question.
i save the information to the file.hsh when i disconnect from the server, but can i save the information on exit too? when i code im not connected to a server (and if i configure the script without connecting i need to redo everything again if i didn't connect before closing mirc), i asking cos i don't know how long time the information is stored in the table after exit, and my computer maybe save the information fast enough to save it in the file, while you have a slower computer it maybe don't get the information in time.
if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
|
|
|
|
|