|
Joined: Aug 2004
Posts: 423
Fjord artisan
|
OP
Fjord artisan
Joined: Aug 2004
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: 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
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
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).
.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
|
|
|
|
Joined: Aug 2004
Posts: 423
Fjord artisan
|
OP
Fjord artisan
Joined: Aug 2004
Posts: 423 |
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 EDITED: okay about the init i'll fix that . 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...???
Last edited by clutz1572; 25/07/05 02:11 PM.
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
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.
if ($did == 3) {
.hdel words $did(1).seltext
did -d $dname 1 $did(1).sel
}
-Andy
|
|
|
|
Joined: Aug 2004
Posts: 423
Fjord artisan
|
OP
Fjord artisan
Joined: Aug 2004
Posts: 423 |
hmmmmm.... it would appear that it's not working..!!?? however, i would think it would but, no
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
This works for me, for the most part. (I think).
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
|
|
|
|
Joined: Aug 2004
Posts: 423
Fjord artisan
|
OP
Fjord artisan
Joined: Aug 2004
Posts: 423 |
just out of desperation and a whim i tried this.. 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 .. go figure
|
|
|
|
Joined: Aug 2004
Posts: 423
Fjord artisan
|
OP
Fjord artisan
Joined: Aug 2004
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 :
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
|
|
|
|
Joined: Dec 2002
Posts: 3,547
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 3,547 |
Maybe something along the lines of..
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
|
|
|
|
|