mIRC: Check if INI-file has a key

373 views Asked by At

I'm trying to see if there is a entry in a ini-file with a user's nick as the key or not. If not; make an entry. If it exists; post a error message.

var %previous = $readini(numbers.ini,Number,$nick)

if(%previous != $null) {
  msg $chan $nick , you have already written %previous .
}
else {
  writeini numbers.ini Number $nick $2
  msg $chan $nick has written $2.
}

What's happening with the script above is that it is never $null, and I can't find anywhere what is returned from $readini if a key is not found.

1

There are 1 answers

2
Patrickdev On

$ini(numbers.ini, Numbers, $nick) will return number N (indicating that the item is the Nth item in that section) if it exists. If it does not exist, it will return $null.

In your case, you'll want something along the lines of

if ($ini(numbers.ini, Numbers, $nick) != $null) {
  msg $chan $nick , you have already written $readini(numbers.ini, Numbers, $nick)
}
else {
  writeini numbers.ini Numbers $nick $2
  msg $chan $nick has written $2.
}