You're looking for mIRC's token identifiers. I would suggest reading the help files (/help token identifiers) to read more about them.
Use $istok()
to check whether the line contains that keyword already:
if ($istok(%keyword, $1, 44)) // Keyword exists
Use $addtok()
to add a new keyword to the line, and then write it to the file:
writeini keyword.ini # $nick $addtok(%keyword, $1, 44)
Use $numtok()
and $gettok()
to create a loop to read all the values:
var %i = 1, %keywords = $readini(cookies.ini, n, channel, nick)
while (%i <= $numtok(%keywords, 44)) {
echo -a Keyword %i $+ : $gettok(%keywords, %i, 44)
inc %i
}
Important note: always use the n
switch with $readini()
(like I did above) when reading data, especially when it's data that users can enter. Without it, $readini()
will evaluate the contents (e.g., $me will be evaluated to your current nickname). Users can inject malicious code this way.
Edit for the inserted question: You are using a while loop to check whether they possess the cookie - it will loop once for every cookie they have (0 loops for no cookies). You don't need this while loop at all, since $istok(%keywords $1, 44)
will take all the keywords and return $true
if $1
is in that list of tokens.
Just the following will suffice:
var %keywords = $readini(keyword.ini,n,$chan,$nick), %cookie = $readini(cookies.ini,n,#,$nick)
if ($istok(%keywords, $1, 44)) {
; the token $1 is in the list of tokens %keywords
msg # you already have this cookie! :(
}
else {
; the token $1 did not appear in the list of tokens %keywords
inc %cookie
writeini cookies.ini $chan $nick %cookie
writeini keyword.ini $chan $nick $addtok(%keywords, $1, 44)
}