mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2017
Posts: 20
Ameglian cow
OP Offline
Ameglian cow
Joined: Jan 2017
Posts: 20
This should be my last question, then I have all the functions that I want for my current bot (and then you are free of my stupid questions :p)!
I want to use a rating system for songs with my bot and I do have everything set up, but I do not have any experience with .ini files (used to store information).
Is it possible to read all the last values and get an average from that?

Kind of like this:

[In the end - Linkin Park]
Vijo - 3
Savian - 5
John - 4
[Other song - you don't know who]
Vijo - 2

(The average being 4 for the Song by LP and the number being the rating everyone gave the song)
I guess you could count the lines of the song with a certain command and then use $calc to get the average, but for that I need to retrieve the values/numbers of everyone for one song.

Is it possible to do this?

As always, thanks in advance!


Streaming games on Twitch, while guiding and helping other players!
www.twitch.tv/vijoplays
Joined: Nov 2013
Posts: 22
Ameglian cow
Offline
Ameglian cow
Joined: Nov 2013
Posts: 22
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.

Link Copied to Clipboard