mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2005
Posts: 24
D
DimWatt Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 24
on *:text:*:*: {
if (%nckalrt == off) { goto noalert }
;the line that caused the error
if ($me isin $1-) { join $chan | echo $chan 4 $nick said your name | /splay -w /sounds/notify.wav }
:noalert
/halt
}

on *:open:?: {
if (%scrquery == off) { goto end }
elseif ($nick == isop #blah1) || ($nick == isvoice #blah1) || ($nick == isop #blah2) { goto end }
else { notice $nick Sorry Room Closed For Repairs! Do Have A Nice Day smile | echo -a $nick has MSG you | close -m $nick }
:end
/halt
}

After the pvt message
there was an error message
/join: insufficient parameters (line 3, nick.mrc)

seems to have happened right after a Query
I couldn't see what was sent so I'm only guessing
But my nick hadn't been used in the channel window

is there a identifier to write around this

Thanks heaps

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Well, supposing I Private Message you and then you try to join a channel. What channel are you joining it wasnt a channel your joining it's a query.

Q: How do you join a query?
A: We don't we make it the active window.

Code:
on *:TEXT:$($+(*,$me,*)):*: {
  if (%nckalert == on) {
    window -a $iif($target !ischan,$nick,$chan)
    echo $target 4 $nick said your name
    splay -w sounds/notify.wav
  }
}


-Andy

Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Just some scripting remarks: stay away from /goto and from /halt.
/halt is only needed to prevent some action from displaying in the default way so you can change the output. Since you didn't use on ^*:TEXT it doesn't work anyway, and it doesn't seem like you want that either.

Scripts can (should) end by running out of commands, you do not have to specifically say 'stop here' at every last script line. If you do need a script to end earlier, use return. This keeps /halt only for really stopping all mIRC output.

I have changed your on OPEN script to use the halt command in the way it's intended: stopping the default mIRC behaviour of opening the query window. You won't have to close it, since it isn't opened at all.


Code:
on *:text:*:#: {
  if (%nckalrt == on) && ($me isin $1-) { 
    window -a $chan
    echo $chan 4 $nick said your name
    play -w /sounds/notify.wav
  }
}
on ^*:open:?: {
  if (%scrquery == off) || ($nick !isreg #blah1) || ($nick isop #blah2) { return }
  else { 
    notice $nick Sorry Room Closed For Repairs! Do Have A Nice Day
    echo -a $nick has MSG you
    halt
  }
}

Joined: Aug 2005
Posts: 24
D
DimWatt Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 24
Thanks Andy

I think the match text " $(*.$me,*)" could help a lot.
the nick alert has failed a couple times when the nick was spelled exactly (seems to be 1 user)
after reading up to understand what you had written
I decided to change the location to # that should take care of the Query

thank you very much for your help Andy

I'll keep that in mind Kelder I've been learning reading other scripts and figuring out what is being done

Thank you very much for you help Kelder

Last edited by DimWatt; 30/08/05 09:52 AM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Kelder, to improve my own coding... why would you use return instead of halt if you need to stop a script before the end? What advantage does that have? Is it more a matter of return being the official way, or is there some actual reason?


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
Quote:
Kelder, to improve my own coding... why would you use return instead of halt if you need to stop a script before the end? What advantage does that have? Is it more a matter of return being the official way, or is there some actual reason?


I would use RETURN over HALT as while it might not effect your script now, you may at some future date modify it to use a ^ event and the HALT command would then have unexpected effects.

and Here is something that I would have normally frowned on.
While if im writing real code, i well endever to have any procedure end by it running out of commands (ie: it reaches the end of the first { })
I think (opion here) that this is not the best option for mirc scripts, im sure they take more processing to get out of the event or alias becuase its interpreted at the time.

ie:
Code:
;I beleive this blah alias is better than the one below
alias blah { 
  if (x == y) {
    ... code ..
    return
  } 
  elseif (x == z) {
    .. code ..
    return
  }
  else { .. code .. }
}
;
; I dont think the below one is as good
;
alias blah { 
  if (x == y) {
    ... code ..
  } 
  elseif (x == z) {
    .. code ..
  }
  else { .. code .. }
}


I first noticed the difference in the xdccklipper check the text in channel alias it was using a GOTO of all things to get to the end of the alias (doing nothing else besides then exiting), so i replaced it with a RETURN and noticed some level of performance increase (this was on a very slow machine so, on a fast machine it would have been hard to gauage any difference)

I assume this is due to the rest of the alias having to be pharsed to find the goto and also even without it having a goto, is has to find the correct condinuing of code point, which then turns out to be a closing } and exiting of the alias.


* oh one other reason i dont use HALT is becuase I mostly write events in alias's something like this...

on ^*:TEXT:!blah:#:{ $blah($chan,$nick,$1-) }
alias -l blah { ...code... | if (some condition) { return HALT } | return }

This allows me to halt the event if i want, or not halt it. And it also allows me to test the alias without having to use a second nick, since i can just call $blah() myself using what ever test data i like, something i find most usefull for debuging.

Joined: Jul 2003
Posts: 655
Fjord artisan
Offline
Fjord artisan
Joined: Jul 2003
Posts: 655
my understanding is as follows.

return will halt ONLY the currently executing script
haltdef will halt ONLY the default text
halt will halt BOTH the default text and the currently executing script

Unless there is a specific need to halt the default text, it is good practice to use return instead. No performance change should occur either way as the engine performs a check in both circumstances (either attempts to halt any default text or determines and returns [value] if present)

Edit: I also agree that the use of goto should be avioded whenever possible. It can cause parts of the script to be parsed multiple times, in turn slowing down the script conciderably.

Last edited by Om3n; 30/08/05 02:28 PM.

"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
If you have another script file loaded after this one, the difference between /halt and /return is
the value of $halted. Using halt to just end the event handler could lead other scripts to incorrectly assume the text is not displayed.

Here's 3 examples:
script1.mrc ->
on ^*:TEXT:erty:*:halt
script2.mrc ->
on *:TEXT:erty:*:echo $target $iif($halted,You didn't see $1-,Nothing to add)


script1.mrc ->
on *:TEXT:erty:*:halt
script2.mrc ->
on *:TEXT:erty:*:echo $target $iif($halted,You didn't see $1-,Nothing to add)

script1.mrc ->
on *:TEXT:erty:*:return
script2.mrc ->
on *:TEXT:erty:*:echo $target $iif($halted,You didn't see $1-,Nothing to add)

Other than that, I just don't lie halt, i never use it. If I need to stop default action, I use /haltdef and then script my own displaying stuff...


DaveC is right about the delay: goto results in the script parser reading all lines untill the :label is found, unused else(if) clause is read and skipped until the closing } So sometimes it might be a good idea to use return even when without it the script would end if that means skipping a lot of code that wouldn't be executed anyway. However,
return
}
is still unneeded...

In conclusion, /return seems to me the more official way, with the least side efects. You can even return a value with it to the calling alias or event handler, halt just kills the entire script right there. You wouldn't want $calc(5+5) to /halt 10 instead of return 10 do you smile

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Ask a simple question, get a book for a response. grin

Thank you all for enlightening me.


Invision Support
#Invision on irc.irchighway.net
Joined: Aug 2005
Posts: 24
D
DimWatt Offline OP
Ameglian cow
OP Offline
Ameglian cow
D
Joined: Aug 2005
Posts: 24
I want to thank you all for such clear examples and the explanations. This has really helped.

Thank you
TeeJay


TeeJay

Link Copied to Clipboard