mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2006
Posts: 79
B
Babel fish
OP Offline
Babel fish
B
Joined: Jun 2006
Posts: 79
I just wanna check who is the highest point .. But dont know how to do

alias yourpoint { .msg #trivia $_pc $todo }
alias _pc {
if (!$hget(point,$nick)) return --
if ($hget(point,$nick)) return $hget(point,$nick)
}
;--
alias todo {
if $hget(point,$nick) is highest { return u`re #1 }
}

or is it posibble to show all the ranks .. yes ? how ? thanks smile

Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
You could cycle through all the entries:
Code:
alias findmax {
  var %n = $hget(point,0).item, %max = 0, %maxnick
  while (%n) {
    if ($hget(point,%n).data > %max) { 
      %max = $v1 | %maxnick = $hget(point,%n) 
    }
    dec %n 
  }
  return %maxnick %max
}


or you could add an entry that records that information and update it every time you change a value:
Code:
alias init {
hmake points

hadd points @max | ;; Using '@' since it can't be in a nickname
;; any other init stuff
}
alias update_points {
  var %nick = $$1, %points = $$2
  hadd points %nick %points
  if (%points > $gettok($hget(points,@max),2,32)) {
    hadd points @max %nick %points 
  }
}


Or you could just have some global variables which store %max_points and %max_nick and do the same as the above. I dislike global vars, though smile


Sais
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Ideally, you should keep track of the max value and update it each time you add/update a nick in the table, as Sais suggested. If for some reason you don't want that though, a method of getting the max values that is faster than looping through $hget().item (which can be quite slow with large tables) is described here.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
That's the basic way I sort hash tables as well. It's quick and efficient. smile


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Code:
alias findmax {
  var %n = $hget(point,0).item, %max = 0, %maxnick
  while (%n) {
    if ($hget(point,%n).data > %max) { 
      %max = $v1 | %maxnick = $hget(point,%n)[color:blue].item[/color] 
    }
    dec %n 
  }
  return %maxnick %max
}

Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
Thanks.

I could have sworn that $hget(hash,N) gave the item name (like almost any of the other identifiers that take name/N as an accessor param)


Sais
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Use .item with that.

$hget(Name,N).item

EDIT: Hm... You probably already realized that from DaveC's post. I should look up further to see what was already posted before replying. smile

Last edited by Riamus2; 26/11/06 09:52 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
It doesn't give the item name because you could have an item named as a number. Requiring .item/.data when using the $hget(table, N) format removes the possibility for conflict.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
Good point. I vaguely remember realising that at some stage. Apparently I forgot again!


Sais

Link Copied to Clipboard