mIRC Homepage

please help. ini file renumber.

Posted By: acpixel

please help. ini file renumber. - 19/08/15 09:14 AM

Ok so i basically have a ini file and it looks somewhat like this

Code:
[#acpixel]
1=test
2=test1
3=test2
4=test3

and so on, and things get added all the time so it is endless.

so what i need is something so that if i have a command that lets people remove #2 it would end up like this,

Code:
[#acpixel]
1=test
3=test2
4=test3


And then the script automaticly fixes it and makes it
Code:
[#acpixel]
1=test
2=test2
3=test3


I dont know if this is possible but if it is i would love some help.
Posted By: Wims

Re: please help. ini file renumber. - 19/08/15 10:59 AM

It's possible but you should work on how not to have to do this, because as you said, if it's endless, mIRC will simply freeze a lot if you have a large amount of data.
Note also that because you used number as the items, you won't be able to use $ini properly, which would be the way to solve that problem. A solution would be to use something else than just numbers, like I<n> where n is the number, but you have a letter before it, making it not just number, then you would be able to do what you asked with:

Code:
alias fixit {
var %a 1
hmake #acpixel
while ($ini(file,#acpixel,%a) != $null) {
hadd #acpixel %a $readini(file,#acpixel,$v1)
inc %a
}
%a = 1
while ($hget(#acpixel,%a) != $null) {
writeini $qt(file) #acpixel I $+ %a $v1
inc %a
}
hfree #acpixel
}
But you shouldn't be doing it like that, use a text file or a @window if you want ordered stuff
Posted By: acpixel

Re: please help. ini file renumber. - 19/08/15 03:12 PM

Thank you @wims


I would do text files but the reason I'm doing this is I'm making a quote system that has a different quote bank for each channel it joins. And I wouldent know how to format or use text files at all. I only ever use ini. So if there's a way you could explain making a numbered system then being able to have a random quote chosen and sent to the channel, or someone types !quote 29 and it would send quote 29. The reason I needed the fix thing was because I needed a way to delete quotes. And if I didn't do a fix. Then it would overlap it's self a whole bunch and break.
Posted By: Wims

Re: please help. ini file renumber. - 19/08/15 03:51 PM

You could create a text file for each channel, just like you would have different section for different channel in your INI file.
Note that even in your perfect world where it works as you want, once you delete quote n3, the old quote n4 becomes the n3 and so on, so you can't rely on fixed number unless you don't delete the quote, but rather mark them as deleted (like Nillens mentioned in that other thread, iirc), that would make the file much bigger but one could rely on the number.
Posted By: acpixel

Re: please help. ini file renumber. - 19/08/15 04:11 PM

Actually I have a different ini for each channel do to a weird maybe bug that I was running into
Posted By: acpixel

Re: please help. ini file renumber. - 19/08/15 04:14 PM

I will probably end up marking them as deleted... But when I do I need a way to make it so that when I type !quote to get a random one, the deleted ones don't show up.
Posted By: Wims

Re: please help. ini file renumber. - 19/08/15 04:29 PM

Which bug? If you have one INI file per channel with only one section, it's not so great..
To avoid getting the one marked as deleted, it's pretty easy, just mark them with something super strange which is unlikely to be a quote, (like $+($chr(1),$chr(2),$chr(3)) ), and when you find a quote, check that it's different from that, if it's equal, just try another quote, pseudo code:

while ($findquote == $deletedmark) noop
echo -a quote: $v1
Posted By: acpixel

Re: please help. ini file renumber. - 19/08/15 04:40 PM

Thanks. I worked for about 5 hours straight and I found that the ini thing works best if I do one ini per channel. I have them all outputting to a folder called quotes. Thanks to you everything works. Thanks <3
Posted By: acpixel

Re: please help. ini file renumber. - 19/08/15 06:47 PM

i have one more question. one what exactly is noop
and two what would $findquote and $deletedmark be set to?

here is my code but idk how to make it leave out my delete tag. which is "asdf1234,,"

Code:
on *:TEXT:!quote:#: {
  set %quote $rand(1, $calc($lines(F:\mIRC\quotes\quotes $+ # $+ .ini) - 2))
  msg $chan $readini(F:\mIRC\quotes\quotes $+ # $+ .ini, n, #, %quote)

}
Posted By: Wims

Re: please help. ini file renumber. - 20/08/15 12:03 AM

Quote:
and I found that the ini thing works best if I do one ini per channel
This must be because as a single INI file you had a lot of lines, but it's not a bug, it's just that INI handling is slow with mIRC script.

/noop is a commmand for doing nothing with the result, usually used with identifier which are not returning a value, but aren't given as command to preserve spaces in parameters, like $hfind, check /help /noop

Code:
on *:TEXT:!quote:#:get_quote $chan
alias $deletedmark return asdf1234,,
alias get_quote {
;as long as the quote we got is the deleted mark, we keep that loop running evaluating $findquote again to find a new quote, the body of the loop itself doesn't need to do anything
while ($findquote($1) == $deletedmark) noop
  msg $1 $v1
}
alias findquote {
var %file $+(F:\mIRC\quotes\quotes,$1,.ini)
return $readini(%file, n, #, $rand(1, $calc($lines(%file) - 2)))
}
© 2021 mIRC Discussion Forums