mIRC Home    About    Download    Register    News    Help

Topic Options
#259850 - 05/02/17 02:43 PM .ini files - Possible to retrieve all values?
VijoPlays Offline
Ameglian cow

Registered: 06/01/17
Posts: 20
Loc: Germany
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

Top
#259981 - 16/02/17 07:40 PM Re: .ini files - Possible to retrieve all values? [Re: VijoPlays]
funfare Offline
Ameglian cow

Registered: 26/11/13
Posts: 22
Loc: Louisiana
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"


Edited by funfare (16/02/17 07:41 PM)

Top