mIRC Home    About    Download    Register    News    Help

Print Thread
A
AWEstun
AWEstun
A
Can someone tell me what is wrong with this:

Code:
/search3 {
  set %hash seen
  set %search QUIT
  var %a = $hfind(%hash,* $+ %search $+ *,0,w).data
  echo -s total: %a
  while (%a) {
    echo -s %a : $hfind(%hash,* $+ %search $+ *,%a,w).data is $hget(%hash,%a).data
    dec %a
  }
}

It's showing weird results, items that down have *QUIT* in them.

Joined: Jul 2006
Posts: 4,022
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,022
Code:
/search3 {
  var %hash seen ,%search QUIT ,%a = $hfind(%hash,$+(*,%search,*),0,w).data
  echo -s total: %a
  while (%a) {
  var %h $hfind(%hash,$+(*,%search,*),%a,w).data
  echo -s %h is $hget(%hash,%h)
    dec %a
  }
}


Edit : It was showing weird result because your code was false, The data of the Nth item is not for sure the data of the N match

Last edited by Wims; 09/06/08 01:05 AM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
A
AWEstun
AWEstun
A
Originally Posted By: Wims
Code:
/search3 {
  var %hash seen ,%search QUIT ,%a = $hfind(%hash,$+(*,%search,*),0,w).data
  echo -s total: %a
  while (%a) {
  var %h $hfind(%hash,$+(*,%search,*),%a,w).data
  echo -s %h is $hget(%hash,%h)
    dec %a
  }
}


Edit : It was showing weird result because your code was false, The data of the Nth item is not for sure the data of the N match


Thanks, I'd wondered about that, but I didn't know how to fix it. What about this code to wildcard search item names? It worked the way I had it, but I updated it to correct the wildcard string. Same result.

Code:
/search {
  var %hash = seen ,%search = apple, %a = 1
  while ($hfind(%hash,$+(*,%search,*),%a,w)) {
    echo -s %a : $hfind(%hash,$+(*,search,*),%a,w) is $hget(%hash,%a).data
    inc %a
  }
}

Joined: Aug 2004
Posts: 7,168
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,168
You have to use the data location returned by the $hfind in the $hget to reference the correct item in the hash table.

For example your code could be searching for the 3rd item that matches the required data, but the 3rd match might be the 50th entry, so $hget(table,3) <which you're currently using> would be the incorrect entry.

Instead try
Code:
/search {
  var %hash = seen ,%search = apple, %a = 1, %b = $hget(%hash,0).item
  while %a <= %b {
    %entry = $hfind(%hash,$+(*,%search,*),%a,w)
    if %entry {
      echo -s %a : %entry is $hget(%hash,%entry).data
    }
    inc %a
  }
} 

A
AWEstun
AWEstun
A
Originally Posted By: RusselB
You have to use the data location returned by the $hfind in the $hget to reference the correct item in the hash table.

For example your code could be searching for the 3rd item that matches the required data, but the 3rd match might be the 50th entry, so $hget(table,3) <which you're currently using> would be the incorrect entry.

Instead try
Code:
/search {
  var %hash = seen ,%search = apple, %a = 1, %b = $hget(%hash,0).item
  while %a <= %b {
    %entry = $hfind(%hash,$+(*,%search,*),%a,w)
    if %entry {
      echo -s %a : %entry is $hget(%hash,%entry).data
    }
    inc %a
  }
} 


echo -s %a : %entry is $hget(%hash,%entry).data

should be

echo -s %a : %entry is $hget(%hash,%entry)

so the data is shown

A
AWEstun
AWEstun
A
Thank you for bringing this to my attention. I have adjusted the search modeules and the usermatch module.


Link Copied to Clipboard