0

Although I'm not not to programming for mIRC, I am new to working with dialog boxes as I previously had no use for them and my clients did not need to use them, therefore until now, I have not delved into them previously.

alias ss {
  dialog -dm setup setup
}
dialog setup {

  ; === Window ===
  title "Script Setup"
  size -1 -1 420 335
  button "OK",1,145 307 73 21, OK
  button "Cancel",2,226 307 73 21
  button "Help",3,307 307 73 21
  ; ==============

  box "Personal Preferences",4, 3 3 493 293
  combo 5,128 60 185 210,sort
  button "Add",6, 323 83 73 21
  button "Edit",7, 323 112 73 21
  button "Delete",8, 323 141 73 21
  button "Reset List",9, 323 170 73 21
}
alias -l update.setup {
  did -r setup 5
  set %temp.total $count(%setup.list,$chr(44))
  set %temp.count 0
  :start
  inc %temp.count 1
  did -a setup 5 $gettok(%setup.list,%temp.count,44)
  if (%temp.count < %temp.total) { goto start }
}
on *:DIALOG:setup:edit:*: {
  if ($did == 5) {
    set %setup.temp.channel $did(5).text
  }
}

on *:DIALOG:setup:sclick:*: {
  ; ====== Channel List Btn's ======
  ; === Add ===
  if ($did == 6) {
    set %setup.list %setup.list $+ %setup.temp.channel $+ ,
    update.setup
  }
  ; === Edit ===
  if ($did == 7) {
  }
  ; === Delete ===
  if ($did == 8) {
    set -u3 %setup.tc %setup.channel.selected $+ ,
    set %setup.list $remove(%setup.list,%setup.tc)
    update.setup
  }
  ; === Reset ===
  if ($did == 9) {
    unset %setup.list
    update.setup
  }
}

I'm trying to make a dialog which functions the same as the options window for adding a new server, however this is to add a new channel whereas I'd actually want there to be no text input on the version above, but instead another dialog open upon clicking on add or edit.

The above would simply be an additional question of which would save myself time setting up another question on here, however my current problem which leads onto this is that upon clicking to delete a channel, no channel deletes and instead the current list merges.

Thank you for any help and/or advice and for providing any time to follow up my question.

Best Regards, Tim

1 Answers1

1

You've got several major issues at your script.

A. You're not displaying the list at dialog initialization.
Solution:

on *:dialog:setup:init:*: update.setup

B. When you got "Ok", "Cancel" buttons, make sure you give them the associated command:

button "Cancel",2,226 307 73 21, cancel

C. Add/Delete/Edit commands for all the following command i used purely "Token Identifiers" so i could maximize the usage of mIRC built in functions. (for further information write at mIRC /help token identifiers) 1. Added testing if entry was already inside our list. this protection help us to avoid identical channel inside our list, and help us better use the remove token. 2. Used "$remtok" identifier for "Delete" command. 3. Used "$input" identifier for simple elegant entry editing. the current editing isn't good programming practice + will cause several bugs. * After every command i placed "update.setup" so it will "refresh" our list with every list change.

D. Proper conditions

Use "if..elseif..else" logic, DO NOT use "if..if..if" method.

E. /ss alias

Change alias logic, now it will create new dialog or if dialog is already open it will maximize and display it.

Bonus: Tweeked the "update.setup" alias

Complete Code

alias ss {
  dialog $iif($dialog(setup), -ve, -dmv) setup setup
}

dialog setup {

  ; === Window ===
  title "Script Setup"
  size -1 -1 420 335
  button "OK",1,145 307 73 21, OK
  button "Cancel",2,226 307 73 21, cancel
  button "Help",3,307 307 73 21
  ; ==============

  box "Personal Preferences",4, 3 3 493 293
  combo 5,128 60 185 210,sort
  button "Add",6, 323 83 73 21
  button "Edit",7, 323 112 73 21
  button "Delete",8, 323 141 73 21
  button "Reset List",9, 323 170 73 21
}

alias -l update.setup {
  did -r setup 5
  var %i = 1, %n = $numtok(%setup.list, 44)
  while (%i <= %n) {
    did -a setup 5 $gettok(%setup.list, %i, 44)
    inc %i
  }
}

on *:dialog:setup:init:*: update.setup

; ====== Channel List Btn's ======
on *:DIALOG:setup:sclick:*: {
  ; === Add ===
  if ($did == 6) {
    if (!$istok(%setup.list,$did(5),44)) {
      set %setup.list $addtok(%setup.list, $did(5), 44)
      update.setup
    }
  }
  ; === Edit ===
  elseif ($did == 7) {
    var %temp.editChannel = $did(5)
    if ($input(Channel to be edited., ye, Channel Editing, %temp.editChannel)) {
      set %setup.list $reptok(%setup.list, %temp.editChannel, $v1, 1, 44)
      update.setup
      dialog -ev setup
    }
  }
  ; === Delete ===
  elseif ($did == 8) {
    set %setup.list $remtok(%setup.list, $did(5), 1, 44)
    update.setup
  }
  ; === Reset ===
  elseif ($did == 9) {
    unset %setup.list
    update.setup
  }
}
Orel Eraki
  • 11,940
  • 3
  • 28
  • 36