mIRC Homepage

little bug with points/ top10 command

Posted By: patrickplays

little bug with points/ top10 command - 17/10/14 12:01 PM

hi
i have a little bug in my code.

my stats.ini looks like this
Code:
[#channel.user1]
messages=122
temp1=4
points=4

[#channel.user2]
messages=12
temp1=1

[#channel.user3]
messages=4
temp1=2

[#channel.user4]
temp1=6


and if i do !top10 it will call top10m do display the top 10 in messages.
but it will incorporate user4.

thanks in advance ._.

Code:
alias -l top10m {
  window -h @. | var %i 1
  while $ini(stats.ini,%i) {
    aline @. $gettok($v1,-1,46) $readini(stats.ini,$v1,messages))
    inc %i
  }
  filter -cetuww 2 32 @. @.
  var %i 1 | while %i <= 10 {
    var %list $addtok(%list,$line(@.,%i),44)
    inc %i
  }
  msg $1 Top 10 (messages) are: $replace(%list,$chr(44),$+($chr(44),$chr(32)))
  window -c @.
}

Posted By: Wims

Re: little bug with points/ top10 command - 17/10/14 12:40 PM

Well the code does what it is asked to do, you must use an if statement to include only the people which have a "messages" item in their section:

Code:
while $ini(stats.ini,%i) {
 aline @. $gettok($v1,-1,46) $readini(stats.ini,$v1,messages))
 inc %i
}
Becomes
Code:
while $ini(stats.ini,%i) {
 var %v $v1
 if ($ini(stats.ini,%v,messages) != $null) aline @. $gettok(%v,-1,46) $readini(stats.ini,%v,messages))
 inc %i
}
Posted By: patrickplays

Re: little bug with points/ top10 command - 17/10/14 08:32 PM

i knew i needed a if somewhere, but i wasnt aware i could put %v1 into a var cry ty

btw is there a more efficient way? because it takes already 5 seconds for a 5k lines .ini frown
it will get a lot bigger in a short time
Posted By: Wims

Re: little bug with points/ top10 command - 17/10/14 09:59 PM

Yes.
INI file are not efficient, you have no tool in mIRC to do efficient lookups. INI should in theory (and in your case, theory applies because you have a lot of entries) only be used to store data on the disk, lookups should be done from a better storage method, here, from a custom window:

on start: load the INI file into a custom window
on exit: save the custom window to the INI file

Right now, your script needs to get datas from the INI file, to nicely format them for /filter to work. Your script does that by looping on each section in the INI file and /aline the result to a window, to then /filter, the loop + aline is what takes 5 secs. What you need to do is to keep a window opened with the data, instead of creating the window each time.
Basically, whenever you are using /writeini to update the value of the "messages" item for a given section, you must also update the data in the custom window

When your script initializes (on start or whatever), create the custom window @., loop on the INI file like you are doing in the current top10 alias and aline the datas.
Now when you want to do a top10, you just use /filter on that window, you can remove the loop on the INI file. Of course you must update the @. window whenever you currently are going to update the "messages" item in the INI file. And to keep using theory, you should only write to the ini file when you are done (or periodically to avoid losing data if mIRC crash for example), basically in this example, you are done when you no longer have to do a top10. But if you update the ini file at the same time you update the custom @. window, it's still going to work, but that's less efficient (you don't need to update the INI file since the data is updated on the custom window)
© 2022 mIRC Discussion Forums