mIRC Home    About    Download    Register    News    Help

Print Thread
#206617 18/11/08 08:25 PM
Joined: Sep 2007
Posts: 202
F
firefox Offline OP
Fjord artisan
OP Offline
Fjord artisan
F
Joined: Sep 2007
Posts: 202
I am still a bit confused as to what 'return' does

Is this a correct interpretation:

alias 1 {
do something
call alias2
do something else
}

alias 2 { do something
return }

and then alias 2 returns to alias 1 and does something else?

firefox #206618 18/11/08 08:30 PM
Joined: Feb 2003
Posts: 3,432
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Feb 2003
Posts: 3,432
Code:
alias test {
  if ($1 == return) { echo -a returning | return }
  echo -a no return
}

trigger:

/test return
/test something else


if ($me != tired) { return } | else { echo -a Get a pot of coffee now $+($me,.) }
firefox #206619 18/11/08 08:51 PM
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
When an alias reaches the end of its code it implicitly returns to the calling code, there's no need to explicitly use return in that case. The return statement is useful when you want to either return from the current alias to the calling code prematurely (ie. before the end of the current alias' code) or if you want it to return a value that can then be used by calling that alias as an identifier.

An example of returning prematurely:
Code:
alias moo {
  if (!$1) {
    echo -a Error: /moo command expects at least one parameter
    return
  }
  echo -a MOO! $1-
}


Obviously in that simple example the second portion of code could have been put in an 'else' block to get the same effect, but there are more complex situations where using return is preferable.

An example of returning a value so the alias can be called as an identifier:
Code:
alias double {
  ; Return double the value of the parameter given
  return $calc($1 * 2)
}


With that code you could then use $double(7) (for example) in code and it would return 14


Spelling mistakes, grammatical errors, and stupid comments are intentional.
firefox #206623 18/11/08 09:53 PM
Joined: Dec 2002
Posts: 2,031
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Dec 2002
Posts: 2,031

Also see the $result identifier which can be used with the /return command.

Code:

alias1 {
  echo -a do something 1
  alias2
  echo -a $result <--
  echo -a do something else
}

alias2 {
  echo -a do something 2
  return something from alias2
}



firefox #206627 19/11/08 12:51 AM
Joined: Jan 2007
Posts: 1,156
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Sorry if Im redundant. I'm not sure if you received an answer to your question.

"Return" has two functions.

Originally Posted By: mIRC help file
The Return command

The /return command halts a currently executing script and allows the calling routine to continue processing.

You can also optionally specify a return value which will be stored in the $result identifier. The $result can then be used in the calling routine.

/return [value]


So /return is a great way to halt a script without halting all currently running scripts. Any questions?

You also can use /return <Result> when creating a custom identifier.

alias custom {
if ($1) { return $+($1,.ini) }
}
example: /echo -a $custom(hello)
result: hello.ini

This is really a pointless alias but it demonstrates using return in this manner.

Any questions?

DJ_Sol #206676 20/11/08 05:17 PM
Joined: Sep 2007
Posts: 202
F
firefox Offline OP
Fjord artisan
OP Offline
Fjord artisan
F
Joined: Sep 2007
Posts: 202
thanks everyone for the info

will post again if i have any issues using it


Link Copied to Clipboard