Hash Table, gros problème...

tidds Messages postés 246 Date d'inscription samedi 1 novembre 2003 Statut Membre Dernière intervention 9 janvier 2006 - 28 oct. 2004 à 22:40
tidds Messages postés 246 Date d'inscription samedi 1 novembre 2003 Statut Membre Dernière intervention 9 janvier 2006 - 29 oct. 2004 à 04:56
Bonsoir à tous,

Dans le but d'ajouter de nouvelles fonctionnalités dans mon add-on Matrix, je voudrais afficher la userlist, lettre par lettre et nick par nick... Voici pour l'instant où j'en suis (ne vous fiez pas à la vitesse d'affichage, elle sera diminuée) :

/*
Thanks for having downloaded this script
Matrix v2.1 by moo
Contact : Tybalt15@hotmail.com or irc.epiknet.org (/query moo)
Use: HELP.txt
Special thanks to Elizio, CoolWave and Sorn_Drixer for helping and their remarks. :]
*/

menu * { 
  - 
  Matrix
  .Red:matrix.choix red
  .Green:matrix.choix green
  .Blue:matrix.choix blue
}
alias matrix {
  if (!$window(@Matrix)) {
    if ($hget(users)) { hfree users }
    hmake users 300    var %i 1, %nbuser $nick($chan,0)
    while (%i <= %nbuser) {
      hadd users $nick($chan,%i) $len($nick($chan,%i))
      inc %i
    }
    hadd users selected $hget(users,$rand(1,$hget(users,0).item)).item
    hadd users count 1
    hadd users pos $calc((245 - ($hget(users,$hget(users,selected)) * 6.5)) / 2)
    window -CkBpdho +tL @Matrix 0 0 245 300
    drawrect -f @Matrix 1 0 0 0 245 300
    if ($hget(tab0)) { hfree tab0 }
    hmake tab0 1
    hadd tab0 loop 0
    var %i = 1
    while (%i <= 20) {
      if ($hget(tab $+ [ %i ])) { hfree tab $+ [ %i ] }
      hmake tab $+ [ %i ] 20
      hadd tab $+ [ %i ] %i $rand(a,z)
      hadd tab $+ [ %i ] vc $rand(15,21)
      hadd tab $+ [ %i ] y
      inc %i
      .timer -m 1 0 matrix.load
    }
  }
}
alias -l matrix.choix {
  if ($hget(matrixcolor)) { hfree matrixcolor }
  hmake matrixcolor 1
  hadd matrixcolor color $1
  hadd matrixcolor speed 4
  hadd matrixcolor brightness 235
  matrix
}
alias -l matrix.alias {
  hadd $1 y $calc($hget($1,y) + $hget($1,vc))
  if ($hget($1,y) > $rand(380,430)) {
    hadd $1 y 0
    var %i = 1
    while (%i <= 20) {
      hadd $1 %i $rand(A,Z)
      inc %i
    }
    if ($hget(matrixcolor,speed) == 1) { hadd $1 vc $rand(3,6) }
    elseif ($hget(matrixcolor,speed) == 2) { hadd $1 vc $rand(6,10) }
    elseif ($hget(matrixcolor,speed) == 3) { hadd $1 vc $rand(10,15) }
    elseif ($hget(matrixcolor,speed) == 4) { hadd $1 vc $rand(15,21) }
    elseif ($hget(matrixcolor,speed) == 5) { hadd $1 vc $rand(21,28) }
    elseif ($hget(matrixcolor,speed) == 6) { hadd $1 vc $rand(28,36) }
    elseif ($hget(matrixcolor,speed) == 7) { hadd $1 vc $rand(36,45) }
    elseif ($hget(matrixcolor,speed) == 8) { hadd $1 vc $rand(45,55) }
    elseif ($hget(matrixcolor,speed) == 9) { hadd $1 vc $rand(55,66) }
    elseif ($hget(matrixcolor,speed) == 10) { hadd $1 vc $rand(66,78) }
  }
  if ($hget(matrixcolor,color) == red) { 
    drawtext -ro @matrix $rgb(255,200,200) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 10)) $rand(a,z)
    var %j = 2
    while (%j <= 7) {
      drawtext -ro @matrix $rgb($calc(255 - (%j * -($hget(matrixcolor,brightness)))),0,0) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 13)) $rand(a,z)
      inc %j
    }
  }
  elseif ($hget(matrixcolor,color) == green) { 
    drawtext -ro @matrix $rgb(200,255,200) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 10)) $rand(a,z)
    var %j = 2
    while (%j <= 7) {
      drawtext -ro @matrix $rgb(0,$calc(255 - (%j * -($hget(matrixcolor,brightness)))),0) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 13)) $rand(a,z)
      inc %j
    }
  }
  else {
    drawtext -ro @matrix $rgb(200,200,255) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 10)) $rand(a,z)
    var %j = 2
    while (%j <= 7) {
      drawtext -ro @matrix $rgb(0,0,$calc(255 - (%j * -($hget(matrixcolor,brightness))))) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 13)) $rand(a,z)
      inc %j
    }
  }
}
alias -l matrix.color { 
  drawtext -ro @matrix $rgb($1,$2,$3) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 10)) $rand(a,z)
  var %j = 2
  while (%j <= 7) {
    drawtext -ro @matrix $rgb($4,$5,$6) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 13)) $rand(a,z)
    inc %j
  }
}
alias -l matrix.loop {
  if ($window(@matrix)) {
    drawrect -fn @Matrix 1 0 0 0 245 300
    drawtext -ron @matrix $rgb(200,255,200) Miltown 40 20 100 MATRIX
    if ($hget(matrixcolor,speed) = 1) { drawtext -ron @matrix $rgb(255,255,255) Verdana 10 2 2 MATRIX SPEED : $hget(matrixcolor,speed) (min) }
    elseif ($hget(matrixcolor,speed) = 10) { drawtext -ron @matrix $rgb(255,255,255) Verdana 10 2 2 MATRIX SPEED : $hget(matrixcolor,speed) (max) }
    else { drawtext -ron @matrix $rgb(255,255,255) Verdana 10 2 2 MATRIX SPEED : $hget(matrixcolor,speed) }
    drawtext -ron @matrix $rgb(255,255,255) Verdana 10 2 12 MATRIX BRIGHTNESS : $hget(matrixcolor,brightness)

    if ($hget(users,count) <= $hget(users,$hget(users,selected))) {
      drawtext -ron @matrix $rgb(255,255,255) Verdana 12 $hget(users,pos) 150 $mid($hget(users,selected),$hget(users,count),1)
      hinc users pos 6
      hinc users count
    }
    else {
      hadd users selected $hget(users,$rand(1,$hget(users,0).item)).item
      hadd users count 1
      hadd users pos $calc((245 - ($hget(users,$hget(users,selected)) * 6.5)) / 2)
      echo -a $hget(users,selected)
    }
    var %i 1, %y -12
    while (%i <= 20) {
      %y = %y + 12
      matrix.alias tab $+ [ %i ] %y
      inc %i
    }
    %y = -12
    .timer -m 1 0 matrix.loop
    drawdot @matrix
    %j = 1
  }
}
alias -l matrix.load.c {
  drawtext -ro @matrix $rgb($1,$2,$1) Miltown 30 20 75 matrix
  drawtext -ro @matrix $rgb($1,$2,$1) Miltown 40 20 75 MATRIX
  drawtext -ro @matrix $rgb($1,$2,$1) Miltown 12 85 125 BY MOO
  drawtext -ro @matrix $rgb($1,$1,$2) "Matrix Code NFI" 15 25 200 WELCOME TO THE REAL WORLD
}
alias -l matrix.load {
  if ($hget(tab0,loop) < 0) {    var %r 0, %g 0
    while (%g <= 255) { matrix.load.c 0 %g | inc %g .07 }
    while (%r <= 200) { matrix.load.c %r 255 | inc %r .3 }
    while (%r >= 0) { matrix.load.c %r 255 | dec %r .3 }
    while (%g >= 0) { matrix.load.c 0 %g | dec %g .07 }
    while (%g <= 255) { drawtext -ro @matrix $rgb(0,%g,0) Miltown 40 20 100 MATRIX | inc %g .07 }
    while (%r <= 200) { drawtext -ro @matrix $rgb(%r,255,%r) Miltown 40 20 100 MATRIX | inc %r .1 }
    .timer 1 1 matrix.load
    hinc tab0 loop
  }
  .timer -m 1 0 matrix.loop
}
alias matrix.close {
  window -c @matrix
  hfree users
  var %i = 0
  while (%i <= 20) {
    hfree tab $+ [ %i ]
    inc %i
  }
}
menu @matrix {
  sclick { matrix.close }
}
on *:keydown:@matrix:*: {
  if (($keyval == 38) && $hget(matrixcolor,speed) != 10) { hinc matrixcolor speed }
  elseif (($keyval == 40) && $hget(matrixcolor,speed) != 1) { hdec matrixcolor speed }
  elseif ($keyval == 39) { hinc matrixcolor brightness }
  elseif ($keyval == 37) { hdec matrixcolor brightness }
  elseif ($keyval == 82) { hadd matrixcolor color red }
  elseif ($keyval == 71) { hadd matrixcolor color green }
  elseif ($keyval == 66) { hadd matrixcolor color blue }
  elseif ($keyval == 27) { matrix.close }
  echo -a $keyval
}


Au bout d'un certain temps, j'obient dans le status (après un debug) "Selected", "Count" ou "Pos".
J'en conclus donc que j'ajoute ces items dans ma htable mais je ne sais pas du tout à quel moment...

Je suppose que je problème surgit à ce moment, mais tout me semble pourtant correct :

else {
      hadd users selected $hget(users,$rand(1,$hget(users,0).item)).item
      hadd users count 1
      hadd users pos $calc((245 - ($hget(users,$hget(users,selected)) * 6.5)) / 2)
      echo -a $hget(users,selected)
    }


Si quelqu'un trouve la solution... :]

3 réponses

tidds Messages postés 246 Date d'inscription samedi 1 novembre 2003 Statut Membre Dernière intervention 9 janvier 2006
28 oct. 2004 à 23:28
Oubliez ce message, je m'y prenais mal de toute façon...
Je voulais charger la nicklist dans une htable pour faire un random sur ses items, mais je n'ai qu'a faire un random sur la nicklist directement !

Bref, cette méthode m'évitera déjà ce problème plus 2 autres problèmes que j'avais envisagé... :]
0
tidds Messages postés 246 Date d'inscription samedi 1 novembre 2003 Statut Membre Dernière intervention 9 janvier 2006
29 oct. 2004 à 04:53
Bon, mon problème est tout autre maintenant...

Par moment, quand je lance le script j'ai ce message d'erreur :

* /drawtext: insufficient parameters (line 125, matrix.mrc)


Le nombre de message d'erreur que je reçoit varie de 3-4 à plus de 10 !

Voici mon code :

menu * {
  -
  Matrix
  .Red:matrix.choix red
  .Green:matrix.choix green
  .Blue:matrix.choix blue
}
alias matrix {
  if (!$window(@Matrix)) {
    $iif($hget(user),hfree user)
    $iif($hget(usertot),hfree usertot)
    $iif($hget(count),hfree count)
    $iif($hget(pos),hfree pos)
    hmake user 1
    hmake usertot 1
    hmake count 1
    hmake pos 1
    window -CkBpdho +tL @Matrix 0 0 245 300
    .timer2 -m 1 0 matrix.user
    drawrect -f @Matrix 1 0 0 0 245 300
    if ($hget(tab0)) { hfree tab0 }
    hmake tab0 1
    hadd tab0 loop 0
    var %i = 1
    while (%i <= 20) {
      if ($hget(tab $+ [ %i ])) { hfree tab $+ [ %i ] }
      hmake tab $+ [ %i ] 20
      hadd tab $+ [ %i ] %i $rand(a,z)
      hadd tab $+ [ %i ] vc $rand(15,21)
      hadd tab $+ [ %i ] y
      inc %i
      .timer -m 1 0 matrix.load
    }
  }
}
alias -l matrix.user {
  if ($window(@Matrix)) {
    var %user $nick($chan,$rand(1,$nick($chan,0)))
    hadd user user %user
    hadd user color 0
    hadd user color.count 0
    hadd user color2 0
    hadd pos pos $int($calc((245 - ($len(%user) * 8)) / 2))
  }
}
alias -l matrix.choix {
  if ($hget(matrixcolor)) { hfree matrixcolor }
  hmake matrixcolor 1
  hadd matrixcolor color $1
  hadd matrixcolor speed 4
  hadd matrixcolor brightness 235
  matrix
}
alias -l matrix.alias {
  hadd $1 y $calc($hget($1,y) + $hget($1,vc))
  if ($hget($1,y) > $rand(380,430)) {
    hadd $1 y 0
    var %i = 1
    while (%i <= 20) {
      hadd $1 %i $rand(A,Z)
      inc %i
    }
    if ($hget(matrixcolor,speed) == 1) { hadd $1 vc $rand(3,6) }
    elseif ($hget(matrixcolor,speed) == 2) { hadd $1 vc $rand(6,10) }
    elseif ($hget(matrixcolor,speed) == 3) { hadd $1 vc $rand(10,15) }
    elseif ($hget(matrixcolor,speed) == 4) { hadd $1 vc $rand(15,21) }
    elseif ($hget(matrixcolor,speed) == 5) { hadd $1 vc $rand(21,28) }
    elseif ($hget(matrixcolor,speed) == 6) { hadd $1 vc $rand(28,36) }
    elseif ($hget(matrixcolor,speed) == 7) { hadd $1 vc $rand(36,45) }
    elseif ($hget(matrixcolor,speed) == 8) { hadd $1 vc $rand(45,55) }
    elseif ($hget(matrixcolor,speed) == 9) { hadd $1 vc $rand(55,66) }
    elseif ($hget(matrixcolor,speed) == 10) { hadd $1 vc $rand(66,78) }
  }
  if ($hget(matrixcolor,color) == red) {
    drawtext -ro @matrix $rgb(255,200,200) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 10)) $rand(a,z)
    var %j = 2
    while (%j <= 7) {
      drawtext -ro @matrix $rgb($calc(255 - (%j * -($hget(matrixcolor,brightness)))),0,0) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 13)) $rand(a,z)
      inc %j
    }
  }
  elseif ($hget(matrixcolor,color) == green) {
    drawtext -ro @matrix $rgb(200,255,200) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 10)) $rand(a,z)
    var %j = 2
    while (%j <= 7) {
      drawtext -ro @matrix $rgb(0,$calc(255 - (%j * -($hget(matrixcolor,brightness)))),0) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 13)) $rand(a,z)
      inc %j
    }
  }
  else {
    drawtext -ro @matrix $rgb(200,200,255) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 10)) $rand(a,z)
    var %j = 2
    while (%j <= 7) {
      drawtext -ro @matrix $rgb(0,0,$calc(255 - (%j * -($hget(matrixcolor,brightness))))) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 13)) $rand(a,z)
      inc %j
    }
  }
}
alias -l matrix.color {
  drawtext -ro @matrix $rgb($1,$2,$3) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 10)) $rand(a,z)
  var %j = 2
  while (%j <= 7) {
    drawtext -ro @matrix $rgb($4,$5,$6) "Matrix Code NFI" 15 $2 $calc($hget($1,y) - (%j * 13)) $rand(a,z)
    inc %j
  }
}
alias -l matrix.loop {
  if ($window(@matrix)) {
    drawrect -fn @Matrix 1 0 0 0 245 300
    drawtext -ron @matrix $rgb(200,255,200) Miltown 40 20 100 MATRIX
    if ($hget(matrixcolor,speed) = 1) { drawtext -ron @matrix $rgb(255,255,255) Verdana 10 2 2 MATRIX SPEED : $hget(matrixcolor,speed) (min) }
    elseif ($hget(matrixcolor,speed) = 10) { drawtext -ron @matrix $rgb(255,255,255) Verdana 10 2 2 MATRIX SPEED : $hget(matrixcolor,speed) (max) }
    else { drawtext -ron @matrix $rgb(255,255,255) Verdana 10 2 2 MATRIX SPEED : $hget(matrixcolor,speed) }
    drawtext -ron @matrix $rgb(255,255,255) Verdana 10 2 12 MATRIX BRIGHTNESS : $hget(matrixcolor,brightness)

    if ($hget(user,color.count) <= 240) {
      drawtext -ron @matrix $rgb(0,$hget(user,color),0) Verdana 12 $hget(pos,pos) 150 $hget(user,user)
      hinc user color 15
      hinc user color.count 15
    }
    elseif (($hget(user,color.count) > 240) && ($hget(user,color.count) <= 285)) {
      drawtext -ron @matrix $rgb($hget(user,color2),255,$hget(user,color2)) Verdana 12 $hget(pos,pos) 150 $hget(user,user)
      hinc user color.count 15
      hinc user color2 85
    }
    elseif (($hget(user,color.count) > 285) && ($hget(user,color.count) <= 345)) {
      drawtext -ron @matrix $rgb($hget(user,color2),255,$hget(user,color2)) Verdana 12 $hget(pos,pos) 150 $hget(user,user)
      hinc user color.count 15
      hdec user color2 85
    }

    elseif (($hget(user,color.count) > 345) && ($hget(user,color.count) <= 600)) {
      drawtext -ron @matrix $rgb(0,$hget(user,color),0) Verdana 12 $hget(pos,pos) 150 $hget(user,user)
      hdec user color 15
      hinc user color.count 15
    }
    else { hadd user color.count 0 | hadd user color2 0 }    var %i 1, %y -12
    while (%i <= 20) {
      %y = %y + 12
      matrix.alias tab $+ [ %i ] %y
      inc %i
    }
    %y = -12
    .timer -m 1 0 matrix.loop
    drawdot @matrix
    %j = 1
  }
}
alias -l matrix.load.c {
  drawtext -ro @matrix $rgb($1,$2,$1) Miltown 30 20 75 matrix
  drawtext -ro @matrix $rgb($1,$2,$1) Miltown 40 20 75 MATRIX
  drawtext -ro @matrix $rgb($1,$2,$1) Miltown 12 85 125 BY MOO
  drawtext -ro @matrix $rgb($1,$1,$2) "Matrix Code NFI" 15 25 200 WELCOME TO THE REAL WORLD
}
alias -l matrix.load {
  if ($hget(tab0,loop) < 0) {    var %r 0, %g 0
    while (%g <= 255) { matrix.load.c 0 %g | inc %g .07 }
    while (%r <= 200) { matrix.load.c %r 255 | inc %r .3 }
    while (%r >= 0) { matrix.load.c %r 255 | dec %r .3 }
    while (%g >= 0) { matrix.load.c 0 %g | dec %g .07 }
    while (%g <= 255) { drawtext -ro @matrix $rgb(0,%g,0) Miltown 40 20 100 MATRIX | inc %g .07 }
    while (%r <= 200) { drawtext -ro @matrix $rgb(%r,255,%r) Miltown 40 20 100 MATRIX | inc %r .1 }
    .timer 1 1 matrix.load
    hinc tab0 loop
  }
  .timer -m 1 0 matrix.loop
}
alias matrix.close {
  window -c @matrix
  .timer* off
  hfree user
  hfree usertot
  hfree count
  hfree pos
  var %i = 0
  while (%i <= 20) {
    hfree tab $+ [ %i ]
    inc %i
  }
}
menu @matrix {
  sclick { matrix.close }
}
on *:keydown:@matrix:*: {
  if (($keyval == 38) && $hget(matrixcolor,speed) != 10) { hinc matrixcolor speed }
  elseif (($keyval == 40) && $hget(matrixcolor,speed) != 1) { hdec matrixcolor speed }
  elseif ($keyval == 39) { hinc matrixcolor brightness }
  elseif ($keyval == 37) { hdec matrixcolor brightness }
  elseif ($keyval == 82) { hadd matrixcolor color red }
  elseif ($keyval == 71) { hadd matrixcolor color green }
  elseif ($keyval == 66) { hadd matrixcolor color blue }
  elseif ($keyval == 27) { matrix.close }
}


Si quelqu'un à le courage de chercher l'erreur, je l'en remercie ! :]
0
tidds Messages postés 246 Date d'inscription samedi 1 novembre 2003 Statut Membre Dernière intervention 9 janvier 2006
29 oct. 2004 à 04:56
Hmm, étant donné que j'ai supprimé quelques lignes de commentaires dans le code ci-dessus, le numéro de ligne dans le message d'erreur est faussé.

En gros, l'erreur est sur le drawtext de ce if :

if ($hget(user,color.count) <= 240) {
drawtext -ron @matrix $rgb(0,$hget(user,color),0) Verdana 12 $hget(pos,pos) 150 $hget(user,user)
hinc user color 15
hinc user color.count 15
}
0
Rejoignez-nous