mIRC Home    About    Download    Register    News    Help

Print Thread
#209970 28/02/09 09:50 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Hello I am closing a custom window with the command: /window -c @name.

Is there any way i can see this with the ON CLOSE event?

on *:close:@:{
if ($target == $+(@,%h_nick)) unset %h_nick
}

This works if I click the X and close it manually, but won't trigger when I use the /window -c command.

Joined: Jul 2006
Posts: 4,163
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,163
This is not needed because if you close it with a command (window -c or /close -@) you know you close it

Code:
alias closewin if ($1 == $+(@,%h_nick)) unset %h_nick
on *:close:@:closewin $target
alias stuff {
...
window -c $+(@,%h_nick)
closewin $+(@,%h_nick)
...
}


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Why isn't it needed? I may have 30 commands I want to trigger whenever I close the window without making an alias. I don't like having a ton of uneeded aliases.

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Use the on signal event. This will trigger when you type /window -c @name in any mirc window.
Code:
on *:INPUT:*:if (/* !iswm $1) || (window -c @ isin $1-) .signal closing
on *:SIGNAL:closing:unset %h_nick

Last edited by Tomao; 28/02/09 08:40 PM.
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Well, the other way arround - knowing if a user or a script closed a certain window does matter, albeit not to every particular script.
If you want to execute the same set of commands in both cases (closed by the user or closed by the script), the obvious sollution is: swap the set of commands for a routine and call this custom alias. Indeed not needed - you may put the 30 commands in both the close event and the closing *whatever* - for 30 commands I'd call it appropriate.

These few "extra" lines of code make you struggle? The alternative for mIRC would be an extra identifier (window closed by the user or closed by a script?), and you'd need "extra" lines of code in the close event of some other script to account for it - No gain at all.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
This input event needs (at least) the && operator...

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
No, Horstl. It's the || operator. Using && won't unset %h_nick

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Quote:
(...) This will trigger when you type /window -c @name in any mirc window.
Code:
on *:INPUT:*:if (/* !iswm $1) || (window -c @ isin $1-) .signal closing
this code reads: if (wilcard string "/*" does NOT match on <first word>) OR ("window -c @" is somewhere in <text>)
... crazy

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
As befuddling as it seems, upon testing it with &&, it didn't unset the variable. Yet with || it did.
Edit - if (/* !iswm $1) isn't needed, so it can be removed.
Code:
on *:INPUT:*:if (window -c @ isin $1-) .signal closing
on *:SIGNAL:closing:unset %h_nick

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
/echo -a window -c @


^ This would trigger your script.

I would just alias window instead:

Code:
alias window {
  if ($1-2 == -c @win) unset %h_nick
  window $1-
}

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Code:
on *:input:*: {
  var %reg = $+(/,^\Q,$readini($mircini,text,commandchar),\E+,(?:(?i)window)) -\w*c\w* (@[^\40]+)/
  if ($regex($1-,%reg)) .signal wclose $regml(1)
}

on *:signal:wclose: echo -ag closing window $1 via editbox
Would take into account:
- possibly different command char
- possible repetitions of command char (///window -c)
- /window -c vs. /window -C (yes, case is important here smile )
- /window -ac (etc.)

And yet you'll miss (examples only):
- /close -@
- //somethingelse | window -c @abc | /window -c @xyz
- //window -c $+(@,$something)
- ...

The code is meant only to show that building your own "parser" to "grab" certain editbox commands isn't that easy (manipulating the /window command will remove some of, but not all the possible pitfalls). For this particular issue, I don't see any use in the attempt at all:

99.99% of custom windows are closed by a user (click on "x", shift-click in treebar, ...) or a script. And, as Wims pointed out, there's no need for events if a script closes the window, because the script "knows" what else to do anyway.
Is there a need to reconfigure/extend the close event, just in case someone prefers to use *script* commands in the editbox? Imho: nope - If you want to close-with-additional-commands via editbox: enter a custom alias that does the trick.

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Great, Hixxy. But that sort of defeats the purpose of using /window -c @win to unset the variable.

Thanks very much, Horstle, for the through explanation with the example provided.

Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

Originally Posted By: Tomao

But that sort of defeats the purpose of using /window -c @win to unset the variable.


That's exactly what hixxy's solution did, unset your variable and closed the window. Is that not what you were requesting?

Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Yes my bad. I take that back. It did very well indeed.

Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
No, window -c @window is performed in a script. Not typed in, otherwise Id just an input event.

I like signals less than aliases. I mean, I use whatever is needed.

My question was if there was a way to see the window close in the close event when the script closes the window. If this is impossible, the answer would be instead of closing the window, perform an alias that closes the window, unsets the variable and whatever else I want to do. At least, this sounds like the best option to me.

(I'd rather use the close event.)


Link Copied to Clipboard