mIRC Homepage
Posted By: alkahol1k halt or return - 16/10/04 02:49 AM
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 ?
Posted By: tidy_trax Re: halt or return - 16/10/04 02:59 AM
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.
Posted By: starbucks_mafia Re: halt or return - 16/10/04 03:01 AM
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.
Posted By: alkahol1k Re: halt or return - 16/10/04 03:07 AM
thanks
© mIRC Discussion Forums