mIRC Home    About    Download    Register    News    Help

Print Thread
#248081 19/09/14 08:54 PM
Joined: Sep 2014
Posts: 52
Babel fish
OP Offline
Babel fish
Joined: Sep 2014
Posts: 52
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.
        }
      } 
    }
  }
}

Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Check the help file: /help /remini


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Sep 2014
Posts: 52
Babel fish
OP Offline
Babel fish
Joined: Sep 2014
Posts: 52
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.

Joined: Jan 2004
Posts: 1,361
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,361
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.

Joined: Sep 2014
Posts: 52
Babel fish
OP Offline
Babel fish
Joined: Sep 2014
Posts: 52
Thank You! I never looked at it the right way I guess. This information helps tremendously.


Link Copied to Clipboard