From WikiChip
Editing mirc/goto statements
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | {{ | + | {{mIRC Guide}} |
'''Goto''' is a command that allows you to jump unconditionally to a specific location within a procedure. Gotos can 'jump' forward or backward within a script but they may not leave the alias or event itself (they cannot jump to any calling routine as well). The goto command tells mIRC to jump to another line which matches a label. | '''Goto''' is a command that allows you to jump unconditionally to a specific location within a procedure. Gotos can 'jump' forward or backward within a script but they may not leave the alias or event itself (they cannot jump to any calling routine as well). The goto command tells mIRC to jump to another line which matches a label. | ||
− | + | ||
Although in many cases the use of gotos can often lead to [[Wikipedia:spaghetti-code|spaghetti-code]]. and can usually be replaced with easier to read and follow [[While Loops - mIRC|while statements]] and [[Conditional statements - mIRC|if statements]], it is still important to understand this command and have it in your toolbox. | Although in many cases the use of gotos can often lead to [[Wikipedia:spaghetti-code|spaghetti-code]]. and can usually be replaced with easier to read and follow [[While Loops - mIRC|while statements]] and [[Conditional statements - mIRC|if statements]], it is still important to understand this command and have it in your toolbox. | ||
Line 14: | Line 14: | ||
The label has to start with the colon symbol (:) and must be a single word.</p> | The label has to start with the colon symbol (:) and must be a single word.</p> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Conditional transfer of control == | == Conditional transfer of control == | ||
Line 84: | Line 43: | ||
== Error Handling == | == Error Handling == | ||
− | Although it is rare to use this feature, the "error" label is a designated goto section for error checking. | + | Although it is rare to use this feature, the "error" label is a designated goto section for error checking. If there is an error in the script, mIRC will execute this section. This gives you the ability to continue with the script regardless of the error. If an error occurs but mIRC cannot locate an error goto label in the current routine, mIRC will propagate back to any calling routine and look for one there. |
− | If there is an error in the script, mIRC | ||
− | If | ||
− | + | <syntaxhighlight lang="mirc">Alias Example { | |
− | + | /* | |
− | + | Second parameters of the $rand identifier is missing. | |
− | + | Deliberate Error | |
− | + | */ | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | <syntaxhighlight lang="mirc"> | ||
− | /* | ||
− | |||
− | |||
− | |||
− | |||
echo -a $rand(1,) | echo -a $rand(1,) | ||
return | return | ||
:error | :error | ||
echo -a Error: $error | echo -a Error: $error | ||
− | } | + | }</syntaxhighlight> |
− | + | ||
− | + | == Error Resetting == | |
− | + | Using the /reseterror you can continue on with the rest of the script. Not resetting the error will halt script execution (in such case, mIRC will keep looking for ":error" in all calling routines). | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | Alias Foo { | + | <syntaxhighlight lang="mirc">Alias Foo { |
echo -a $FooBar | echo -a $FooBar | ||
} | } | ||
Line 143: | Line 71: | ||
reseterror | reseterror | ||
return 1000 | return 1000 | ||
− | } | + | }</syntaxhighlight> |
− | </syntaxhighlight> | + | |
− | + | Although the code might look a little confusing, bear with me. Calling alias /Foo will echo what alias FooBar returns. Alias foobar will return what alias bar returns. Because alias bar errors out (since $mid is missing a few parameters) , the "error" section of the foobar alias will get executed, echoing Error followed by the error message and returning 1000 to alias foo. The /reseterror command effectively prevents mIRC from halting the script and allows it to finish executing. |