mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2011
Posts: 2
M
Bowl of petunias
OP Offline
Bowl of petunias
M
Joined: Aug 2011
Posts: 2
I'm working on a couple of scripts right now, thankfully having the same basic framework, but I ran into an issue. I'm trying to write to an ini somewhat like this:
.writeini blah.ini $nick lines +1

where it would write to an ini named blah, the section name would be the nickname that created the event, the variable would be "lines", and it would take a 0 and turn it into a 1, or turn a 1 into a 2, etc. basically, counting each time someone created a text event and recording it.

Also would need help reading the .ini. I'm pretty new to scripting. I just can't figure out how to use variables in the command.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You can't just increment a number in a file like that. You have to first read in the current number, then increment it and write back the incremented number.

Code:
  var %value = $readini(blah.ini,$nick,lines)
  inc %value
  writeini -n blah.ini $nick lines %value


Now, you can of course increment the value right in the var line or in the writeini line. This just breaks it down so you can see the process.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2011
Posts: 2
M
Bowl of petunias
OP Offline
Bowl of petunias
M
Joined: Aug 2011
Posts: 2
Thanks a ton! So, here's the technical part. How would I read back the 5 highest incremented numbers out of an .ini?

Last edited by MadSc13n41s4; 10/08/11 04:33 PM.
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
To my knowledge you'd have to read them all, then sort them, probably using /filter

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The best option is to keep track of which are the top 5 instead of trying to figure it out when reading the file. Another option is to use a hash table instead of an ini file and then you can save and filter it and quickly find out the top 5 or 10 or whatever without having to keep constant track of who is top.


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: MadSc13n41s4
Thanks a ton! So, here's the technical part. How would I read back the 5 highest incremented numbers out of an .ini?


here's a simple and quick method:

Code:
; /top5

alias top5 {

  if ($window(@top5)) window -c @top5
  window -h @top5

  var %i = 1
  while ($ini(blah.ini, %i)) {
    aline @top5 $v1 $+ : $readini(blah.ini, $v1, lines)
    inc %i
  }

  filter -wwteuc 2 32 @top5 @top5

  var %i = 1, %out
  while (%i <= 5) {
    %out = %out $+ , $line(@top5, %i)
    inc %i
  }

  window -c @top5
  echo -eag $mid(%out, 3)
}


first add nick & line values to a window named @top5 using a loop with $ini / $readini, sort that window with /filter, then collect the first 5 lines with a second loop.


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Link Copied to Clipboard