mIRC Home    About    Download    Register    News    Help

Print Thread
#138226 26/12/05 04:56 AM
Joined: Jul 2005
Posts: 7
F
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jul 2005
Posts: 7
Hi! I'm trying to get an $hfind to work. What I'm doing is filtering a list of names into a window called @BOT.filter and then using hfind in an alias to pick each name, find it in a hash table and aline back to the window the name plus the result of the hfind (if any). Unfortunately it is going through the list of nicks and only returning the last entry.

Here's the code:
Code:
alias pre.bot.filter {
  var %pbf.numberoflines = $line(@BOT.filter,0)
  var %c = 1
  while (%pbf.numberoflines >= %c) {
    var %pbf.line = $line(@BOT.filter,%pbf.numberoflines)
    dline @BOT.filter %pbf.numberoflines
    var %pbf.numtok = $numtok(%pbf.line,44)
    while (%pbf.numtok >= %c) {
      var %pbf.name = $gettok(%pbf.line,%pbf.numtok,44)
      var %pbf.hfind = $hfind(hashtable,* $+ %pbf.name $+ *,1,w)
      aline @BOT.filter %pbf.name %pbf.hfind
      dec %pbf.numtok
    }
    dec %pbf.numberoflines
  }
}


It starts out with two lines of about 50 names each like:
nick1, nick2, nick3, nick4...
nick59, nick60, nick61, nick62...

and it's taking them like it's supposed to one by one and spitting them out like:

nick1 hfind-result
nick2
nick3
nick4
.....
nick59 hfind-result
nick60
nick61
nick62

(the window sorts them)

problem is that nick62 and some of the others do have an hfind result but it's not being added (just the last name it gets to)

Any Help would be appreciated.
FTLNewsFeed

#138227 26/12/05 06:52 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
The problem is the 1 in your $hfind line. That makes it return the first match, and only the first match, even if there are other matches. Try the following code.
Code:
 alias pre.bot.filter {
  var %pbf.numberoflines = $line(@BOT.filter,0), %c = 1
  while (%c <= %pbf.numberoflines) {
    var %pbf.line = $line(@BOT.filter,%c), %pbf.numtok = $numtok(%pbf.line,44), %d = 1
    dline @BOT.filter %c
    while (%d <= %pbf.numtok) {
      var %pbf.name = $gettok(%pbf.line,%pbf.numtok,44), %entries = $hfind(hashtable,* $+ %pbf.name $+ *,0,w)
      while %entries {
        var %pbf.hfind = $hfind(hashtable,* $+ %pbf.name $+ *,%entries,w)
        aline @BOT.filter %pbf.name %pbf.hfind
        dec %entries
      }
      inc %d
    }
    inc %c
  }
}

 

#138228 26/12/05 05:10 PM
Joined: Jul 2005
Posts: 7
F
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jul 2005
Posts: 7
I see what you're saying RusselB, but the problem is that even with more than one entry, it still should return the first entry and it's not even doing that... and in this case there IS only one entry so the straight off hfind should be returning it.

FTLNewsFeed

P.S. I just tried your code and it did what I feared, it returned the last hfind of each line and none of the others.

Last edited by FTLNewsFeed; 26/12/05 05:47 PM.
#138229 26/12/05 06:11 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I tried your code.. This is the code I used in order to test it:
Code:
pre.bot.filter {
[color:blue]
  ; Create Hash Table
  if ($hget(hashtable)) hfree hashtable
  hmake hashtable 5
  hadd hashtable nick1 Data for nick 1
  hadd hashtable nick2 Data for nick 2
  hadd hashtable nick3 Data for nick 3
  hadd hashtable nick4 Data for nick 4
  hadd hashtable nick5 Data for nick 5
  hadd hashtable nick6 Data for nick 6

  ; Create and populate window
  window -sl @BOT.filter
  clear @BOT-filter
  aline @BOT.filter nick1,nick2,nick3
  aline @BOT.filter nick4,nick5,nick6
[/color]

  ; Parse data and read hashtable
  var %pbf.numberoflines = $line(@BOT.filter,0)
  var %c = 1
  while (%pbf.numberoflines >= %c) {
    var %pbf.line = $line(@BOT.filter,%pbf.numberoflines)
    dline @BOT.filter %pbf.numberoflines
    var %pbf.numtok = $numtok(%pbf.line,44)
    while (%pbf.numtok >= %c) {
      var %pbf.name = $gettok(%pbf.line,%pbf.numtok,44)
      var %pbf.hfind = [color:red]$hget(hashtable,[/color]$hfind(hashtable,* $+ %pbf.name $+ *,1,w)[color:red])[/color]
      aline @BOT.filter %pbf.name %pbf.hfind
      dec %pbf.numtok
    }
    dec %pbf.numberoflines
  }
}


Blue is code I added to create the window and hashtable for testing purposes.

Red is part of your code that I changed. The $hfind identifier returns the item name, not the data, so I added the $hget part to return the data.

Assuming that your hashtable is populated with the appropriate items, your code should have written something like this to your window:

nick1 nick1
nick2 nick2
nick3 nick3

The problem may be with another part of your code.

-genius_at_work

#138230 27/12/05 12:49 AM
Joined: Jul 2005
Posts: 7
F
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jul 2005
Posts: 7
Actually I just found out what was wrong, and am coming down from being steamed, but it seems that the hfind was including the space before the nick in the match and thus not returning any results. But what really made me mad is that I had tested for that before I wrote one line of code with a $gettok and it displayed in my status window WITHOUT the space before the nick!

FTLNewsFeed


Link Copied to Clipboard