|
|
MadSc13n41s4
|
MadSc13n41s4
|
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,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
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.
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.
|
|
|
|
MadSc13n41s4
|
MadSc13n41s4
|
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,168
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
To my knowledge you'd have to read them all, then sort them, probably using /filter
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
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.
|
|
|
|
Joined: Feb 2006
Posts: 523
Fjord artisan
|
Fjord artisan
Joined: Feb 2006
Posts: 523 |
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:
; /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
|
|
|
|
|
|