mIRC Homepage
Posted By: clutz1572 more questions for acro script... - 27/01/05 04:47 PM
hello again,

i have 2 questions for my script.
FIRST, i was thinking of adding the ability to edit an entry that already exists in the hash, but have only been able to succesfully recall the item into editbox. when i try to pull the item's data, the way the code is now it just duplicates the item name in the data editbox..(hope i'm explaining this ok..)

and secondly, have some check boxes (alough i originaly wanted to use radios) to select options but i'm having a problem with having it when is checked the other is deactivated.. they both call on a readini alais and it presents a problem when both are set on. how would somthing like this be done?

here's the code :
Code:
on *:INPUT:*:{ 
  if ( $left($1,1) != / ) { acro $1- }
}
alias -l amsw { writeini -n $+(",$mircdirdat\ini\,$1,") $2 $3 $$4- } 
alias -l amsr  return $readini $+",$mircdirdat\ini\,$1,"),n,$2,$$3)
alias -l acro {
  var %i = $getacro($1-)
  if (%i) {
    msg $active %i
    halt
  }
}
alias -l getacro {
  if (!$hget(amacros)) { return }
  var %i = 1
  var %r
  while ($gettok($1-,%i,32)) {
    var %j = $v1
    if ($hget(amacros,%j)) { %j = $v1 }
    %r = %r %j
    inc %i
  }
  if ($amsr(settings.ini,Acro,colorcaps) == On) {
    return $colorcap(%r)
  }
  elseif ($amsr(settings.ini,Acro,rcolorcaps) == On) {
    return $rcolorcap(%r) 
  }
  else
  return %r
}
alias -l colorcap {
  var %v = 1, %u
  while $gettok($1,%v,32) != $null {
    %u = %u %ac1 $+ $upper($left($v1,1)) $+ %ac2 $+ $mid($v1,2) 
    inc %v
  }
  return %u
}

alias -l rcolorcap {
  var %v = 1, %u
  while $gettok($1,%v,32) != $null {
    %u = %u  $+ $rand(3,14) $+ $upper($left($v1,1)) $+  $+ $rand(3,14) $+ $mid($v1,2)
    inc %v
  }
  return %u
}

dialog acro_test {
  title $amlogo ACRONYMS
  size -1 -1 314 200
  option dbu
  list 1, 16 64 82 107, size vsbar
  edit "", 3, 16 46 82 10
  edit "", 4, 147 46 150 10
  list 2, 147 64 149 107, size vsbar
  button "Add Acro", 5, 91 25 37 9
  button "Del Acro", 6, 133 25 37 9
  text "-= Input TexT =-", 7, 30 35 41 8
  text "-= Output TexT =-", 8, 202 35 45 8
  text "A", 9, 120 56 4 8
  text "C", 10, 120 69 5 7
  text "R", 11, 120 81 5 7
  text "O", 12, 120 93 5 7
  text "N", 13, 120 105 4 7
  text "Y", 14, 120 117 4 8
  text "M", 15, 120 129 5 8
  text "S", 16, 120 141 4 8
  button "Okay", 17, 104 186 37 12, ok
  button "Ascii Table", 18, 111 13 37 9
  text "-= OR =-", 21, 247 15 20 7
  check "Enable Acro Colors", 20, 225 6 63 9
  check "Enable Random Colors", 19, 225 21 65 9
}

on *:dialog:acro_test:*:*: {
  if ($devent == init) {
    if !$hget(amacros) { hamke amacros 100 | hload amacros $amshdir(amsacros.hsh) }
    var %x = 1
    while $hget(amacros,%x).item {
      did -a $dname 1 $v1
      inc %x
    }
    var %y = 1
    while $hget(amacros,%y).data {
      did -a $dname 2 $v1
      inc %y
    }
    if ($amsr(settings.ini,Acro,colorcaps) == On) { did -c $dname 20 }
    if ($amsr(settings.ini,Acro,rcolorcaps) == On) { did -c $dname 19 }
  }
 [color:red]  if ($devent == dclick) {
    if ($did == 1) {
      if $did(1).seltext || $did(2).seltext {
        $hget(amacros).item {
          did -a $dname 3 $v1
        }
        $hget(amacros,$v1).data {
          did -a $dname 4 $v1
        }
      }
    }
  }
  [/color] 
  if ($devent == sclick) {
    if ($did == 5) {
      if ($did($dname,3) == $null) && ($did($dname,4) != $null) { $awarno | $awarnc }
      elseif ($did($dname,4) == $null) && ($did($dname,3) != $null) { $awarno | $awarnc }
      else {
        if ($hget(amacros)) {
          hadd amacros $did($dname,3).text $did(acro_test,4).text
          did -a acro_test 1 $did($dname,3).text
          did -a acro_test 2 $did($dname,4).text 
          did -r $dname 3,4
        }
      }
    }
    if ($did == 6) {
      if ($did(acro_test,1).sel) {
        if ($hget(amacros)) {
          set %line $did(acro_test,1).sel
          hdel amacros $did(acro_test,1).seltext
          did -d acro_test 1 %line
          did -d acro_test 2 %line
        }
      }
    }
    if ($did == 18) { odialog ascii_table ascii_table }
   [color:red]if ($did == 19) {
      /amsw settings.ini Acro rcolorcaps $iif($did(19).state,On,Off))
      /amsw settings.ini Acro colorcaps $iif($did(20).state,Off,On))
    }
    if ($did == 20) {
      /amsw settings.ini Acro colorcaps $iif($did(20).state,On,Off))
      /amsw settings.ini Acro rcolorcaps $iif($did(19).state,Off,On))
    }
  }
  [/color]   
  if ($devent == close) {
    if ($dialog(ascii_table)) { dialog -x ascii_table }
    .hsave -o amacros dat\hsh\amsacros.hsh
  }
}  

the code in red is where the my questions lies..

if anyone could help,, thanks in advance
Posted By: JAFO Re: more questions for acro script... - 27/01/05 07:03 PM
Just an idea, but couldnt you remove and then add the edited acro? I know you just want to edit it , but removing the original and then adding the edited would work. As far as the second part , i never tried anything like that, so i will ask why there is an $iif statement for id 19 and 20 in the controls for $did 19 , and the same with the controls for $did 20?
Posted By: Iori Re: more questions for acro script... - 28/01/05 01:45 AM
Well for the first, /did -o overwrites an existing entry

did -o dialog ID line# data
Posted By: clutz1572 Re: more questions for acro script... - 28/01/05 05:03 AM

JAFO said :
Quote:
Just an idea, but couldnt you remove and then add the edited acro? I know you just want to edit it , but removing the original and then adding the edited would work. As far as the second part , i never tried anything like that, so i will ask why there is an $iif statement for id 19 and 20 in the controls for $did 19 , and the same with the controls for $did 20?


well JAFO,
that would be too easy...lol but in fact that's what i was trying to avoid.. my idea was to dclick on it and bring both the item and the data into the appropriate edit boxes.. i fugured it might pose some hint of professionalism to the script... and as for the $iif statements... they basicly set the data for an item in a ini file 1 or 0(on,off)... whay i have both in the ids?? well it was a non successful test to get this right...

and Iori said :
Quote:
Well for the first, /did -o overwrites an existing entry

did -o dialog ID line# data


how would this affect the hash?? by doing as you suggest would i have to add another button..??
Posted By: Iori Re: more questions for acro script... - 28/01/05 06:12 AM
You'd also have to add the item back to the table with the new data of course. smile
If only the replace data has changed
- hadd table item data
(Hash tables can't have duplicate items.)

If it is the acronym itself that has changed, /hdel the old item as well.
- hdel table item
- hadd table item data
Posted By: tidy_trax Re: more questions for acro script... - 28/01/05 10:25 AM
Some of your code could be cleaned up a lot as well, for example:

Code:
alias -l acro {
  var %i = $getacro($1-)
  if (%i) {
    msg $active %i
    halt
  }
}


Could be:

Code:
alias -l acro { msg $active $$getacro($1-) }
Posted By: clutz1572 Re: more questions for acro script... - 28/01/05 04:26 PM
okay...

i see what your saying now.... grin

thanks for that!!
Posted By: clutz1572 Re: more questions for acro script... - 28/01/05 04:33 PM
tidy_trax said :
Quote:
Some of your code could be cleaned up a lot as well, for example:

Code:
--------------------------------------------------------------------------------

alias -l acro { var %i = $getacro($1-) if (%i) { msg $active %i halt }}

--------------------------------------------------------------------------------


Could be:

Code:
--------------------------------------------------------------------------------

alias -l acro { msg $active $$getacro($1-) }

--------------------------------------------------------------------------------


thanks for that tip tidy!!!

okay that pretty much answers my editing question...

now i would still like to the switch thing when is clicked on the other is off.. since both cannot be on together at the same time..

i was thinking about my radio idea.. would it just be better to use the radios and have them set a var either on or off... would that work?..
Posted By: Iori Re: more questions for acro script... - 28/01/05 10:41 PM
It is more common to use radio controls for this but checkboxes can work
Code:
    if ($did isnum 19-20) {
      if $did == 20 && $did(20).state { did -u acro_test 19 }
      elseif $did == 19 && $did(19).state { did -u acro_test 20 }
      amsw settings.ini Acro colorcaps $iif($did(20).state,On,Off))
      amsw settings.ini Acro rcolorcaps $iif($did(19).state,On,Off))
    }
Posted By: clutz1572 Re: more questions for acro script... - 29/01/05 05:03 AM
okay,
thats the idea that i was trying for but i didn't know how to achieve it...... thats a good example use of isnum(for me anyways) i would have been banging my head against the wall. cause i wouldn't have looked there!

thanks Iori
Posted By: Iori Re: more questions for acro script... - 29/01/05 01:52 PM
No probs smile

BTW: If you store On or Off settings as 1 or 0 instead, you can shorten things a little like so
  • amsw settings.ini Acro colorcaps $did(20).state
    amsw settings.ini Acro rcolorcaps $did(19).state

and in the init event like
  • if $amsr(settings.ini,Acro,colorcaps) { did -c $dname 20 }
    elseif $amsr(settings.ini,Acro,rcolorcaps) { did -c $dname 19 }

^elseif here because it should be one or none but not both, so if 20 is "on" then the 19 won't be
Posted By: clutz1572 Re: more questions for acro script... - 30/01/05 04:43 AM
that makes sense.... plus short n sweet wink
Posted By: clutz1572 Re: more questions for acro script... - 30/01/05 10:28 PM
good news i've figured out my dclick problem that i originaly stated about dclicking on the acro in the list boxes and bringing them up into the edit boxes for editing! grin ( see code in green)
now, i have one additional problem with this that i cant figure out. i have added the edit button to well, edit an entry.. and it removes the item from the hash and replaces it (so to speak), also it adds it to the list boxes but it doesn't remove the old entry from them.... ( see code in red)

heres the code as i have it now :
Code:
on *:INPUT:*:{ if ( $left($1,1) != / ) { acro $1- } }
alias -l acro { msg $active $$getacro($1-) }
alias -l getacro {
  if (!$hget(amacros)) { return }
  var %i = 1, %r
  while ($gettok($1-,%i,32)) {
    var %j = $v1
    if ($hget(amacros,%j)) { %j = $v1 }
    %r = %r %j
    inc %i
  }
  if ($amsr(settings.ini,Acro,colorcaps) == On) { return $colorcap(%r) }
  elseif ($amsr(settings.ini,Acro,rcolorcaps) == On) { return $rcolorcap(%r) }
  else
  return %r
}
alias -l colorcap {
  var %v = 1, %u
  while $gettok($1,%v,32) != $null {
    %u = %u %ac1 $+ $upper($left($v1,1)) $+ %ac2 $+ $mid($v1,2) 
    inc %v
  }
  return %u
}
alias -l rcolorcap {
  var %v = 1, %u
  while $gettok($1,%v,32) != $null {
    %u = %u  $+ $rand(3,14) $+ $upper($left($v1,1)) $+  $+ $rand(3,14) $+ $mid($v1,2)
    inc %v
  }
  return %u
}
dialog acro_test {
  title $amlogo ACRONYMS
  size -1 -1 314 200
  option dbu
  list 1, 16 64 82 107, size vsbar
  edit "", 3, 16 46 82 10
  edit "", 4, 147 46 150 10
  list 2, 147 64 149 107, size vsbar
  button "Add Acro", 5, 91 25 37 9
  button "Del Acro", 6, 133 25 37 9
  text "-= Input TexT =-", 7, 30 35 41 8
  text "-= Output TexT =-", 8, 202 35 45 8
  text "A", 9, 120 56 4 8
  text "C", 10, 120 69 5 7
  text "R", 11, 120 81 5 7
  text "O", 12, 120 93 5 7
  text "N", 13, 120 105 4 7
  text "Y", 14, 120 117 4 8
  text "M", 15, 120 129 5 8
  text "S", 16, 120 141 4 8
  button "Okay", 17, 104 186 37 12, ok
  button "Ascii Table", 18, 111 13 37 9
  text "-= OR =-", 21, 247 15 20 7
  radio "Enable Acro Colors", 20, 225 6 63 9
  radio "Enable Random Colors", 19, 225 21 65 9
  button "Edit Acro", 22, 18 15 37 9
}

on *:dialog:acro_test:*:*: {
  if ($devent == init) {
    if !$hget(amacros) { hamke amacros 100 | hload amacros $amshdir(amsacros.hsh) }
    var %x = 1
    while $hget(amacros,%x).item {
      did -a $dname 1 $v1
      inc %x
    }
    var %y = 1
    while $hget(amacros,%y).data {
      did -a $dname 2 $v1
      inc %y
    }
    if ($amsr(settings.ini,Acro,colorcaps) == On) { did -c $dname 20 }
    if ($amsr(settings.ini,Acro,rcolorcaps) == On) { did -c $dname 19 }
  }
  if ($devent == sclick) {
    if ($did == 5) {
      if ($did($dname,3) == $null) && ($did($dname,4) != $null) { $awarno | $awarnc }
      elseif ($did($dname,4) == $null) && ($did($dname,3) != $null) { $awarno | $awarnc }
      else {
        if ($hget(amacros)) {
          hadd amacros $did($dname,3).text $did(acro_test,4).text
          did -a acro_test 1 $did($dname,3).text
          did -a acro_test 2 $did($dname,4).text 
          did -r $dname 3,4
        }
      }
    }
    if ($did == 6) {
      if ($did(acro_test,1).sel) {
        if ($hget(amacros)) {
          var = %line $did(acro_test,1).sel
          hdel amacros $did(acro_test,1).seltext
          did -d acro_test 1 %line
          did -d acro_test 2 %line
        }
      }
    }
    if ($did == 18) { odialog ascii_table ascii_table }
    if ($did isnum 19-20) {
      if $did == 20 && $did(20).state { did -u acro_test 19 }
      elseif $did == 19 && $did(19).state { did -u acro_test 20 }
      amsw settings.ini Acro colorcaps $iif($did(20).state,On,Off))
      amsw settings.ini Acro rcolorcaps $iif($did(19).state,On,Off))
    }
     [color:red]if ($did == 22) {
      if ($hget(amacros)) { 
        hdel amacros $did($dname,3).text {
          if $did(1).sel || $did(2).sel {  
            did -d $dname 1  $did($dname,3).text
            did -d $dname 2  $did($dname,4).text
          }
          .hadd amacros $did($dname,3).text $did(acro_test,4).text
          did -a acro_test 1 $did($dname,3).text 
          did -a acro_test 2 $did($dname,4).text 
          did -r $dname 3,4
        }
      }
    }
  }
  [/color] 
  [color:green]if ($devent == dclick) {
    if $did(1).seltext {
      did -ra $dname 3 $v1 | did -u $dname 1
      did -ra $dname 4 $hget(amacros,$v1)
    }
    if $did(2).seltext {
      did -ra $dname 4 $v1 | did -u $dname 2
      did -ra $dname 3 $hfind(amacros,$v1).data
    }
  }
  [/color]
   if ($devent == close) {
    if ($dialog(ascii_table)) { dialog -x ascii_table }
    .hsave -o amacros dat\hsh\amsacros.hsh
  }
}
  


how would i be able to fix this??
thanks in advance
© mIRC Discussion Forums