if ($did == 4) { did -a $dname 3 1 }
if ($did == 5) { did -a $dname 3 2 }
if ($did == 6) { did -a $dname 3 3 }
if ($did == 7) { did -a $dname 3 4 }
You can shrink the script by making the \'$did\'s which are setting numbers into one line (on two occasions) like this example (for the above section):
if ($did >= 4) && ($did <= 7) did -a $dname 3 $calc($did - 3)
You could use $right($calc($did - 3),1) for $did up to 13 in this case (that would return 0). :)