mIRC Home    About    Download    Register    News    Help

Print Thread
halt or return #100746 16/10/04 02:49 AM
Joined: Nov 2003
Posts: 257
A
alkahol1k Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: Nov 2003
Posts: 257
A friend on my network said that its better to use .return then it is to use .halt . Is this true? If so why is it better ?

Re: halt or return #100747 16/10/04 02:59 AM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
It depends on the situation, halt will stop the current script, as well as all "parent scripts", return will only stop the current script.

Eg:

Code:
alias test {
  if ($istok(return halt,$1,32)) { test $+ $1 }
  echo -a 1
}


Code:
alias testreturn {
  echo -a 1
  return
}


Code:
alias testhalt {
  echo -a 1
  halt
}


/test return - You will see that the return in the "testreturn" alias only stops that alias from running.

/test halt - You will see that the halt in the "testhalt" alias will stop that alias, but also the /test alias from running.


New username: hixxy
Re: halt or return #100748 16/10/04 03:01 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
It depends on the situation. return ends the current scope (ie. alias or event) and returns control to the calling scope (ie. an alias), whereas halt just stops execution of the script outright.

ie.:
Code:
alias moo1 {
  echo 4 -a before
  moo2
  echo 4 -a after
}

alias moo2 {
  [color:blue]return[/color]
  echo -a you'll never see this
}

Typing /moo1 will echo:
before
after

However if you change the return to halt it will only echo:
before

Typically you'd use halt when a 'fatal' error occurs in your script, and you'd use return just to break out of an alias.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: halt or return #100749 16/10/04 03:07 AM
Joined: Nov 2003
Posts: 257
A
alkahol1k Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: Nov 2003
Posts: 257
thanks