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. | ||
Line 54: | Line 54: | ||
goto label | goto label | ||
} | } | ||
− | </syntaxhighlight>The first /goto label statement gets mIRC to parse the rest as token, probably just words, and :label is found | + | </syntaxhighlight>The first /goto label statement gets mIRC to parse the rest as token, probably just words, and :label is found, %test is increased to 1 and then to 2, proving that the label is found. |
== Conditional transfer of control == | == Conditional transfer of control == | ||
Line 85: | Line 85: | ||
== 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 try to find an :error label in the current routine. | If there is an error in the script, mIRC try to find an :error label in the current routine. | ||
If no :error label is found in the current routine, mIRC will propagate the error backward to any calling routine and look for an :error label in those routines. | If no :error label is found in the current routine, mIRC will propagate the error backward to any calling routine and look for an :error label in those routines. | ||
− | + | This gives you the ability to continue with the script regardless of the error if you want. | |
− | This gives you the ability to continue with the script | ||
− | |||
After catching an error with :error, you must check for an error by checking $error with a typical /if statement to make sure you reached the :error part because of an error and not because the script is just reaching that point. | After catching an error with :error, you must check for an error by checking $error with a typical /if statement to make sure you reached the :error part because of an error and not because the script is just reaching that point. | ||
If you want to keep going with the code, use /reseterror as soon as possible, this reset the error (and therefore $error's value), mIRC leaves the error state and you can safely execute anything you want. | If you want to keep going with the code, use /reseterror as soon as possible, this reset the error (and therefore $error's value), mIRC leaves the error state and you can safely execute anything you want. | ||
+ | If you try to execute anything else than /reseterror after reaching an :error label because of an error, mIRC can broke (see examples). | ||
+ | Indeed, here mIRC is in an error state, yet it must still process your code somehow to allow you to *at least* check for error and reset it, so it's unclear what you can do and what you can't do besides an if statement on $error followed by /reseterror. You would think that since mIRC is somehow forced to allow you to use the scripting engine to check for error and reset it, you could be able to do anything even without calling /reseterror first (still after checking for $error), this is not true, the exact list of features that are working in this situation are unknown, it's recommended not to do anything before using /reseterror in this situation. | ||
− | + | <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 | ||
Line 111: | Line 107: | ||
echo -a Error: $error | echo -a Error: $error | ||
} | } | ||
− | + | ;In this case, we try to execute something else than /reseterror after reaching :error, for some reasons, that $regsubex gets mIRC to silentely halts while inside a routine | |
− | + | ;You should get the first echo 'ok' and an echo '> $str(ab,2000)' is expected, but you shouldn't see it. | |
− | + | ||
− | |||
− | |||
alias testgoto { | alias testgoto { | ||
if | if | ||
Line 121: | Line 115: | ||
echo -a ok | echo -a > $regsubex($str(ab,2000),/(a*)b*(a*)*b/,) | echo -a ok | echo -a > $regsubex($str(ab,2000),/(a*)b*(a*)*b/,) | ||
} | } | ||
− | /* | + | |
+ | /* | ||
Although this example might look a little confusing, bear with me: | Although this example might look a little confusing, bear with me: | ||
Calling alias /Foo will echo what alias FooBar returns. | Calling alias /Foo will echo what alias FooBar returns. | ||
Line 146: | Line 141: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | [[Category:mIRC | + | [[Category:mIRC]] |