mIRC Home    About    Download    Register    News    Help

Print Thread
#165430 26/11/06 03:01 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I have a menu that allows me to store nicks in a hash table.
For each of these nicks, there are a number of associated items.
Example: other nicks that person has used, a sound file, and a list of words that I need to monitor from certain nicks.

Getting all this to display using a dialog is easy. Make a list of nicks, then when a nick is selected, show the other nicks, the sound file and the words list.

What I want to do (if possible) is have all that available through the menu system, rather than a dialog.

Any and all help will be appreciated, and credits will be added to the final code when complete.

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
here's a very basic example:

Code:
menu status {
  Info
  .$submenu($info($1))
}

alias -l info {
  if (!$istok(begin end,$1,32)) return $hget(table,$1).item :echo -a $hget(table,$1).data
}


when the status win is right clicked, the list of hash tables items will be viewable under Info which will echo their corresponding data values when clicked. i believe you can modify this to suit your needs shocked


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Thanks...this is the first time I've come across a need to use $submenu. I wasn't even completely sure that I needed to do it that way, and your example makes a lot of sense.

If I have further questions along this line, I'll post as a reply to here (unless it's a long time in the future)

Joined: Dec 2004
Posts: 66
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2004
Posts: 66
Hi Russel, I just did something like that today, in my nicklist pops:

Code:
$iif($snick(#,0) == 1,Info)
.$submenu($InfoSubMenu($1)) 


And in remotes:

Code:
alias InfoSubMenu {
  if ($1 == begin) {
    var  %Info = $WhoHash.Info4Nick($snick(#,1))
    if (!%Info) return
    var %NicIdntAddy = $gettok(%Info,2,151)
    var %NicIdnt     = $gettok(%NicIdntAddy,1,64)

    set %InfoSub.Nick $gettok(%NicIdnt,1,33) : noop
    set %InfoSub.Real $replace($gettok(%Info,3,151),¡,!) : noop
    set %InfoSub.Idnt $gettok(%NicIdnt,2,33) @: noop
    set %InfoSub.Host $gettok(%NicIdntAddy,2,64)

    if ($hfind(xRef,%InfoSub.Host $+ —*,1,w)) {
      set %InfoSub.IP   $gettok($v1,2,151) : noop
      set %InfoSub.Mask $gettok($v1,3,151) : noop
    }
    return
  }

  if ($1 == 1) return %InfoSub.Nick
  if ($1 == 2) return %InfoSub.Real
  if ($1 == 3) return %InfoSub.Idnt
  if ($1 == 4) return %InfoSub.Host : noop
  if ($1 == 5) return %InfoSub.IP
  if ($1 == 6) return %InfoSub.Mask
  if ($1 == end) unset %InfoSub.*
}


$submenu is called once when the main popup that it is a part is opened, not each time your mouse cursor hovers over the heading of the submenu, in this case “Info”.

“$1 == begin is” first, so it can do the work of finding the data, unpacking it, and getting it ready for display. In this case I don’t have the submenu items do anything, it’s more like a tool tip.

jaytea’s code looks cool, depends on where you want the info displayed.

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Thanks for your help. I've done some more work, unfortunately this isn't working the way I'd like.

Hopefully the following code will be sufficient to indicate what I want, even though I'm not getting it.
Code:
 menu * {
  Nick Message Notification
  .Notify List has $iif($hget(Watch,Notify) = 1,1 entry,$iif($hget(Watch,Notify),$v1,no) entries)
  ..$iif($hget(Watch,Notify),Add,Set) Notification Nick : notify.list add $input(Notification Nick,e,Add Notification Nick,$iif($1,$1,$me))
  ..$iif($hget(Watch,Notify),Remove Notification Nick) : notify.list del $input(Notification Nick,e,Remove Notification Nick,$iif($1,$1,$me))
  .-
  .$iif($hget(Watch,Notify),Select Nick) : noop
  ..$submenu($Notify_Nicks($1))
}

alias -l notify_nicks {
  $iif(Notify.* iswm $hget(Watch,$1).item,return $gettok($v2,-1,46))
}

alias -l notify.list {
  var %nicks = $replace($2-,$chr(44),$chr(32)), %a = 1, %b = $numtok(%nicks,32)
  while %a <= %b {
    $iif($1 == add,.hadd -m,.hdel) Watch $+(Notify.,$gettok(%nicks,%a,32)) $true
    inc %a
    .hinc Watch Notify
  }
}
 


In case what I want can't be determined, what I'm looking for is an accessable list of the nicks in the hash table where each item in the hash table is in the format of Notify.<nick>

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
There is a subtle error in this, which unfortunately won't give an error message but will cause unnecessary (and quite possibly noticeable) delay in popup creation.

The problem is that even if $1 exceeds the number of hash table items, the alias won't return $null; it will return
$hget().item : $hget().data
And while both identifiers are $null, the whole thing is not, as it evaluates to ":". This will cause mirc to keep incrementing $1 and call $submeneu over and over, until the internal limit is hit (in 6.21 it seems to be 250, I believe it used to be 500). This means 250 - <items number> unnecessary calls.

Making the alias return $null once $1 becomes larger than $hget(table,0).item signals mirc that the submenu alias has added all items, so in the next $submenu call, mirc will fill $1 with "end":

Code:
menu status {
  Info
  .$submenu($info($1))
}
alias -l info {
  if !$istok(begin end,$1,32) &amp;&amp; * iswm $hget(table,$1).item {
    return $v2 :echo -a $hget(table,$v2)
  }
}
The info alias implicitly returns $null if $hget(table,$1).item is $null (meaning $1 became larger than $hget(table,0).item). I also changed $hget(table,$1).data to $hget(table,$v2) as the latter is faster (it doesn't search through the list as $hget().data does) and if there's a place where you need the last bit of speed is real-time popup creation smile


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
ooh yeah i didn't notice the alias wasn't returning $null at the end laugh seems you can even use:

Code:
alias -l info {
  if (!$istok(begin end,$1,32)) return [color:red]$[/color]$hget(table,$1).item :echo -a $hget(table,$1).data
}


which should be quicker still as it eliminates an extra condition shocked


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
a few mistakes there, in popups a parent item can't include a command i.e. .$iif($hget(Watch,Notify),Select Nick) : noop should not have that noop command there, nor the colon

the submenu items created by the alias SHOULD have commands though :P and try to avoid replacing simple if statements with $iif. so the alias becomes:

Code:
alias -l notify_nicks {
  if (Notify.* iswm $hget(Watch,$1).item) return $mid($v2,8) :noop
}


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Thanks for the reply and the explanation. Unfortunately when I try it with my code, I'm still not getting the nicks. Also I noticed that the parent item is greyed. I replaced my alias with the one you provided, and made the changes to the parent item line. Aside from that, my code is still the same as before.

I added
Code:
echo 4 -a $1 $hget(Watch,$1).item
to the alias, and it returned
begin 3
1 Notify
end 3


When I manually check the entries in the hash table, I get this
Notify
Notify.RusselB-afk
Notify.Truth-or-Dare-Master


So as you can see there's a problem somewhere...I'm just not sure where or how to fix it...hopefully you can do so, with an explanation (although your posts so far have been great for explanations, so that seems like a redundant request).

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
when it looks at the first item "Notify", Notify.* fails as a wildmatch so the alias returns $null and the submenu stops trying to load extra items shocked change it to a wildmatch which reflects all the items in the hash table and perhaps change $mid($v2,8) to something which will return the portion of the item name you want, maybe $gettok($v2,-1,46) as you originally had since $gettok(Notify,-1,46) => Notify and $gettok(Notify.nick,-1,46) => nick


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Your problem rises from the fact you have other variables in the hashtable namely the "NOTIFY" itemname, however any other itemname well cause problems, becuase you dont want to display anything for them, thus returning a $null, and any $null return outside of the $submenu(BEGIN) well trip off the $submenu(END) event, so you never get past 1 (which just happens to match to the NOTIFY item name, it might as easy have occured as 12th in list of 36, which would have made tracking why it stopped even harder!)

I have created the bellow adjustments, i added in a fake.setup alias, becuase i didnt have the table, i assume this is correct info, absed on what i read in your scripts.

Code:
alias fake.setup {
  hfree -sw Watch
  hadd -sm Watch Notify 2
  hadd -sm Watch Notify.RusselB-afk $true
  hadd -sm Watch Notify.Truth-or-Dare-Master $true
}
 
menu * {
  Nick Message Notification
  .Notify List has $iif($hget(Watch,Notify) = 1,1 entry,$iif($hget(Watch,Notify),$v1,no) entries)
  ..$iif($hget(Watch,Notify),Add,Set) Notification Nick : notify.list add $input(Notification Nick,e,Add Notification Nick,$iif($1,$1,$me))
  ..$iif($hget(Watch,Notify),Remove Notification Nick) : notify.list del $input(Notification Nick,e,Remove Notification Nick,$iif($1,$1,$me))
  .-
  .$iif($hget(Watch,Notify),Select Nick)
  ..$submenu($Notify_Nicks($1))
}
 
alias -l notify_nicks { if (($1 isnum 1-) &amp;&amp; ($hfind(Watch,Notify.*,$1,w))) { return $mid($v1,8) : ///ECHO -at SELECTED $mid($v1,8) } }
 
alias -l notify.list {
  var %nicks = $replace($2-,$chr(44),$chr(32)), %a = 1, %b = $numtok(%nicks,32)
  while %a &lt;= %b {
    if     (($1 == add) &amp;&amp; (!$hget(Watch,$+(Notify.,$gettok(%nicks,%a,32))))) {
      .hadd -m Watch $+(Notify.,$gettok(%nicks,%a,32)) $true
      .hinc -m Watch Notify
    }
    elseif (($1 == del) &amp;&amp; ( $hget(Watch,$+(Notify.,$gettok(%nicks,%a,32))))) {
      .hdel Watch $+(Notify.,$gettok(%nicks,%a,32))
      .hdec Watch Notify
    }
    inc %a
  }
}


What i did
(1) in MENU i removed the ":noop" from the "Select Nick" line, other wise it doesnt submenu the $submenu under that option.
(2) replaced notify_nicks it now ignores "begin" & "end" and uses $hfind to only match itemsnamed NOTIFY.*
(3) shame on you for notify.list :-) it was incrementing the WATCH hash table item NOTIFY even if it was a DEL action, and also not checking if they were new or existing items
(4) added a ///ECHO to notify_nicks as a demonstration of something u can do with each nick you select in the menu, obviously you wanted to do something with them i assume.

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Thank you very much. That explains a lot and works perfectly.

Now that I've got that part working (with your assistance, and you name will be going into the credits section of the completed code), I'm able to start on the next step.

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
lol, leave my name out of it :-), i might one day find myself having to answer questions as to what my involvment was :-), I freely release anything i type (beisdes my cheques) to the public domain!

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
RusselB omits DaveC's nick from the Credits section per his request


Link Copied to Clipboard