Hey guys. So I was asked by alhammer to make him a Word Count script that counts his words (On Input) not everyone elses (On Text). And it works pretty good, but I need 3rd party perspective to see how it can be improved (touched up) or possibly shortened. I've just thought of a couple of things, saying how many entries in the dialog, the choice to clear all entries and I forgot to add a On Start event to make the hash table and load in (wordcount.dat) but other than that anything else?

Here's the code:

Code:
dialog wordcount {
  title "Word Count"
  size -1 -1 190 145
  option dbu
  list 1, 8 13 86 117, size
  list 2, 95 13 86 117, size
  text "        Words                                          Number Of Words", 3, 29 3 148 8
  button "Close",4, 7 133 175 10
}

on 1:dialog:wordcount:init:*: {
  var %x = $hget(wordcount,0).item
  while (%x) {
    if ($dialog(wordcount)) {
      did -a wordcount 1 $str($chr(160),20) $hget(wordcount,%x).item
      did -a wordcount 2 $str($chr(160),25) $hget(wordcount,%x).data
    }
    dec %x
  }
}

On *:dialog:wordcount:sclick:4: { dialog -x $dname $dname }

On *:dialog:wordcount:close:0: { hsave -i wordcount wordcount.dat }

On *:input:*: {
  if ($left($1,1) == /) { return $1- }
  else {
    if (!$hget(wordcount)) hmake wordcount 1000
    var %x = $numtok($1-,32)
    while (%x) {
      if ($hget(wordcount,$gettok($1-,%x,32))) { hadd wordcount $gettok($1-,%x,32) $calc($hget(wordcount,$gettok($1-,%x,32)) + 1) }
      if (!$hget(wordcount,$gettok($1-,%x,32))) { hadd wordcount $gettok($1-,%x,32) 1 }
      dec %x
    }
  }
}

alias wordcount {
  if (!$1) && (!$dialog(wordcount)) dialog -dm wordcount wordcount 
  if ($hget(wordcount,$1)) { echo -a * /count: You have said $1 $hget(wordcount,$1) time(s) }
}