mIRC Homepage
Posted By: paper0rplastic remini help. Stuck. - 19/09/14 08:54 PM
I am trying to delete a specific item from an ini file and I am failing. Through trial and error, I was able to delete the last line or the first line from the ini, but not a specific item. The adding an item works fine. Any help would be greatly appreciated. Here is what I have so far.

Code:
on *:text:!weapon *:#: {
  if (%Gamescript.On. [ $+ [ $chan ] ] != $null) {
    if ($nick isop $chan) {
      var %k = $+($chan)
      var %n $ini(weapons.ini,#,0)
      if ($2 == add) {
        inc %n 
        writeini weapons.ini %k %n $3-
        msg $chan The weapon " $+ $3- $+ " has been added.
      }
      if ($2 == delete) {
        if { I don't know what goes here?
          msg $chan The weapon " $+ $3- $+ " was removed.
        }
        else {
          msg $chan The weapon " $+ $3- $+ " was not found.
        }
      } 
    }
  }
}
Posted By: westor Re: remini help. Stuck. - 19/09/14 09:38 PM
Check the help file: /help /remini
Posted By: paper0rplastic Re: remini help. Stuck. - 19/09/14 10:01 PM
I did that and that was how I was able to remove either the last item or the first item. Didn't help my situation sadly.
Posted By: Loki12583 Re: remini help. Stuck. - 19/09/14 10:32 PM
Entries in an ini are stored as key value pairs. You reference the values by their keys.

If you are trying to store a list of items with no meaningful key and the index does not matter, I suggest you store the items as the key instead of the value.

Code:
var %file = weapons.ini, %section = $chan

writeini %file %section axe 1
writeini %file %section sword 1
writeini %file %section bow 1

remini weapons.ini %section sword
echo -ag $ini(%file,%section,2)


If you care about the order, you will need to manage changing all the indices yourself when you delete items.

If you ever use $read or $readini, make sure to use the "n" switch so that the text is not evaluated: $readini(%file,n,$chan,axe). Failing to do so leaves your system vulnerable to malicious users.
Posted By: paper0rplastic Re: remini help. Stuck. - 19/09/14 11:01 PM
Thank You! I never looked at it the right way I guess. This information helps tremendously.
© mIRC Discussion Forums