mIRC Home    About    Download    Register    News    Help

Topic Options
#126087 - 25/07/05 04:31 AM issues with hash/dialog
clutz1572 Offline
Fjord artisan

Registered: 16/08/04
Posts: 423
hello again,

i am trying out the hload/hsave -n switch, but am having some difficulty with some rather basic things.. with the -n switch it saves the file as data which is ok thats what i want, but the problem lies with hadd and hdel.. i've managed to fenagle the add button in my dialog for testing purposes but, i know it isn't correct. and i cant figure out how to delete a entry from the hash using this format, because when you use the -n switch while saving/loading it makes it a data file only and sets the item is a numeric refference .. like so :
* Item: 1 Value: word
* Item: 2 Value: word1
* Item: 3 value: word2
* Item: 4 Value: word3
heres what i have thus far:
Code:
dialog wordlist {
  title "Word List"
  size -1 -1 106 127
  option dbu
  combo 1, 40 15 60 92, size
  button "Add", 2, 4 39 30 12
  button "Delete", 3, 4 66 30 12
  button "Save", 4, 30 114 37 12, ok
  check "Enable/Disable", 5, 5 3 50 9
}
on *:dialog:wordlist:*:*: {
  if ($devent == init) {
    if !$hget(words) { .hmake words 10 | .hload -n words  words.dat } 
    var %i = 1 
    while $hget(words,%i).data { 
      did -a $dname 1 $v1 
      inc %i 
    }
    if (%endisable) { did -c $dname 5 }
  }
  if ($devent == sclick) {
    if ($did == 2) {
      .hadd badwords $did(1) $did(1) | did -a $dname 1 $did(1) | did -d $dname 1 $did(1)
    }
    if ($did == 3) { 
      .hdel words did(1).sel | did -d $dname 1 $did(1).sel
    }
    if ($did == 4) { .hsave -n words words.dat }
    if ($did == 5) { .set %endisable $iif($did(5).state,1,0)) }
    if ($did($dname,5).state == 1) { did -c $dname 5 } | else { did -u $dname 5 }
  }
}
  


if anyone can help it would be appreciated greatly!
thanks in advance

Top
#126088 - 25/07/05 03:04 PM Re: issues with hash/dialog
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
Hey dude, the only thing I saw faulty in your code is referenced at line number 26.

Your trying to add an item to table name (badwords) not (words).

Code:
.hadd [color:red]badwords[/color] $did(1) $did(1) | did -a $dname 1 $did(1) | did -d $dname 1 $did(1)


Just a suggestion but for your INIT event I'd also check to see if words.dat exists so it only loads data if it's $true.

-Andy

Top
#126089 - 25/07/05 03:05 PM Re: issues with hash/dialog
clutz1572 Offline
Fjord artisan

Registered: 16/08/04
Posts: 423
Code:
if ($devent == sclick) {
    if ($did == 2) { 
     .hadd badwords $did(1) $did(1) | did -a $dname 1 $did(1) | did -d $dname 1 $did(1) 
   }
  


this is a typo... left over from previous testings.. it's .hadd words.. OOps, sorry blush

EDITED:
okay about the init i'll fix that smile . but, the deleting function i 'm not sure how to do.. i don't know how to get it to delete the numeric value, since thats what i think i would have to do.. yes/no...???


Edited by clutz1572 (25/07/05 03:11 PM)

Top
#126090 - 25/07/05 03:16 PM Re: issues with hash/dialog
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
I think I've found it, you're trying to delete the item .hdel words $did(1).sel where $did(1).sel is the line number, $did(1).seltext is the selected text. smile

Code:
    if ($did == 3) { 
      .hdel words $did(1).seltext
      did -d $dname 1 $did(1).sel
    }


-Andy

Top
#126091 - 25/07/05 03:39 PM Re: issues with hash/dialog
clutz1572 Offline
Fjord artisan

Registered: 16/08/04
Posts: 423
hmmmmm....

it would appear that it's not working..!!??
however, i would think it would but, no frown

Top
#126092 - 25/07/05 03:42 PM Re: issues with hash/dialog
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
This works for me, for the most part. (I think).

Code:
dialog wordlist {
  title "Word List"
  size -1 -1 106 127
  option dbu
  combo 1, 40 15 60 92, size
  button "Add", 2, 4 39 30 12
  button "Delete", 3, 4 66 30 12
  button "Save", 4, 30 114 37 12, ok
  check "Enable/Disable", 5, 5 3 50 9
}
on *:dialog:wordlist:*:*: {
  if ($devent == init) {
    if (!$hget(words)) { 
      .hmake words 10 
      if ($isfile(words.dat)) hload -n words words.dat 
    } 
    var %i = 1 
    while $hget(words,%i).data { 
      did -a $dname 1 $v1 
      inc %i 
    }
    if (%endisable) { did -c $dname 5 }
  }
  if ($devent == sclick) {
    if ($did == 2) {
      .hadd words $did(1) $did(1) | did -a $dname 1 $did(1) | did -d $dname 1 $did(1)
    }
    if ($did == 3) { 
      .hdel words $did(1).seltext
      did -d $dname 1 $did(1).sel
    }
    if ($did == 5) { .set %endisable $iif($did(5).state,1,0)) }
    if ($did($dname,5).state == 1) { did -c $dname 5 } | else { did -u $dname 5 }
  }
  if ($devent == close) hsave -n words words.dat
}


-Andy

Top
#126093 - 25/07/05 04:00 PM Re: issues with hash/dialog
clutz1572 Offline
Fjord artisan

Registered: 16/08/04
Posts: 423
just out of desperation and a whim i tried this..

Code:
if ($did == 3) { 
      var %i = 1 
      while $hget(words,%i).data {
        .hdel words $did(1).seltext
        inc %i
      }
      did -d $dname 1 $did(1).sel
    }
  


and it's working ... so far confused..

go figure

Top
#126094 - 25/07/05 05:21 PM Re: issues with hash/dialog
clutz1572 Offline
Fjord artisan

Registered: 16/08/04
Posts: 423
okay, now i have another question ....

i posted before about the use of $read and how it would be used in search txt files for a match in a incoming/outgoing text..(i never did get it going). but, i think searching the hash table would be faster.. so, i ask (again) how would this be done for an on input event using the above as an example.. i think it would start off with some thing like :
Code:
 On *:Input:*: {
   if (($left($1,1) != /) && (!$ctrlenter)) {
     if (!$hget(words)) { return }
     tokenize 32 $1-
    if ($1- iswm $hget(words,$v1),1,W).data ) { do stuff } 
 


anyways i have had no luck with that..

so, as you fine people can see i need some help with this...
thanks again in advance

Top
#126095 - 25/07/05 05:33 PM Re: issues with hash/dialog
SladeKraven Offline
Planetary brain

Registered: 19/12/02
Posts: 3547
Loc: Kent, England
Maybe something along the lines of..

Code:
On *:Input:*: {   
  if (($left($1,1) != /) && (!$ctrlenter)) {   
    if (!$hget(words)) { return } 
    var %x = $hget(words,0).item
    while (%x) {
      if ($istok($strip($1-),$hget(words,%x).data,32)) { dostuff }
      dec %x
    }
  }
}


-Andy

Top