be sure to use "=" in your ini file rather than "-"

INI (saved as songs.ini):
Code:
[In the end - Linkin Park]
Vijo=3
Savian=5
John=4
[Other song - you don't know who]
Vijo=2


mircscript:
Code:
alias songaverage {

  var %path songs.ini

  var %song $1-
  var %e 0
  var %avg 0
  var %tot $ini(%path,%song,0)
  while ( %e <= $ini(%path,%song,0) ) {
    var %value $readini(%path,%song,$ini(%path,%song,%e))
    var %avg $calc(%avg + %value)
    inc %e
  }
  if ( %tot == 0 ) {
    return 0
  }
  else {
    return $calc(%avg / %tot)
  }
}


usage:
Code:
$songaverage(In the end - Linkin Park)


^ returns "4"

Last edited by funfare; 16/02/17 07:41 PM.