Disable: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Grotfang
No edit summary
imported>Bale
mNo edit summary
 
(9 intermediate revisions by 4 users not shown)
Line 6: Line 6:


name={{#var:name}}|
name={{#var:name}}|
function_category=Miscellaneous|


function1={{Function|
function1={{Function|
Line 17: Line 16:
}}|
}}|


function_description=This function allows you to disable commands and/or functions by name. String {{pspan|func}} specifies the name of a CLI command or ASH function that you do not wish to be carried out. Note these include custom ASH functions (that you name yourself), but not aliases.</p>
function_description=This function allows you to disable commands and/or functions by name. String {{pspan|func}} specifies the name of a CLI command or ASH function that you do not wish to be carried out. Note these include custom ASH functions (that you name yourself), but not aliases.
<p>Mafia has an internal array of function names which are disabled. At the start of each session, this array starts empty. Disable adds names to this array and mafia will not allow functions to be called that are named after any on the disabled list (with the exception of disable and enable). This is useful for debugging scripts, as you can quickly disable functions from the top of a script without digging through the code. In addition, when a disabled function is called, mafia will print a line informing you of this fact, while not acting on it.</p><p>Important considerations:
 
<ol>
Mafia has an internal array of function names which are disabled. At the start of each session, this array starts empty. Disable adds names to this array and mafia will not allow functions to be called that are named after any on the disabled list (with the exception of disable and enable). This is useful for debugging scripts, as you can quickly disable functions from the top of a script without digging through the code. In addition, when a disabled function is called, mafia will print a line informing you of this fact, while not acting on it.
<li>Mafia cannot differentiate between scripts that call functions of the same name. If function "foo" is disabled from script one, it will still be disabled when you run script two, unless you enable "foo" or restart mafia.</li>
 
<li>Remember that CLI commands will be disabled if they have the same name (or can be disabled deliberately with this function).</li>
Important considerations:
<li>If a disabled function is incorporated into a condition (eg. "if(disabled_function())" ), then mafia will not just skip the entire conditional. If an else statement is present, the condition is treated as false and the else code will be performed.</li>
#Mafia cannot differentiate between scripts that call functions of the same name. If function "foo" is disabled from script one, it will still be disabled when you run script two, unless you enable "foo" or restart mafia.
<li>Using "all" as the string parameter will disable all ASH functions including enable. This will require a restart of KoLmafia to resolve, so use with care. It also disables the usual logout function, so will require exiting mafia by clicking "X".</li>
#Remember that CLI commands will be disabled if they have the same name (or can be disabled deliberately with this function).
<li>Despite "all" working in the manner specified above, disable() and enable() cannot be disabled using disable() when specified individually. The only way to disable enable() is to use "disable("all")".</li>
#A disabled function still returns a value - the default value for its declared return type (false, 0, "", $item[none], an empty map, etc.).  If a disabled function is incorporated into a condition (eg. "if(disabled_function())" ), then mafia will not just skip the entire conditional - execution will continue as normal, based on that default value.
</ol>|
#Using "all" as the string parameter will disable all ASH and CLI functions with the exception of enable and disable. Therefore, to re-enable all functions, you must type "enable all" into the CLI - ASH enable("all") would technically work, but at that point you'd have no way of invoking a script that contains it.
#disable() and enable() cannot be individually disabled using disable(), either.
&nbsp;|


code1={{CodeSample|
code1={{CodeSample|
title=Code Samples|
title=Code Samples|
description=This mini scriptlet has a bug in it that makes it loop. I want to test what is making the script run oddly, but can't see immediately where the looping conditional is. I can use disable to knock out functions sequentially to test where the fault arises.|
description=This mini scriptlet generates a map that is outputted to a data file. In testing you might not want to do this every time, so you can disable map_to_file().|
code=
code=
<syntaxhighlight>
<syntaxhighlight>
disable("adventure_me");
disable("map_to_file");
void adventure_me(){
  int my_adv = my_adventures();
  while(my_adv > 0){
      adventure(1 , $location[giant's castle]);
  }
  return;
}
 
void main(){
  adventure_me();
  print("Finish");
}
</syntaxhighlight>
</syntaxhighlight>
}}|
}}|
Line 50: Line 39:
see_also={{SeeAlso|enable}}|
see_also={{SeeAlso|enable}}|
}}
}}
[[Category:Miscellaneous Functions]]

Latest revision as of 05:32, 22 May 2010

Function Syntax

void disable(string func )

  • func is the name of the function you wish to disable.

This function allows you to disable commands and/or functions by name. String func specifies the name of a CLI command or ASH function that you do not wish to be carried out. Note these include custom ASH functions (that you name yourself), but not aliases. Mafia has an internal array of function names which are disabled. At the start of each session, this array starts empty. Disable adds names to this array and mafia will not allow functions to be called that are named after any on the disabled list (with the exception of disable and enable). This is useful for debugging scripts, as you can quickly disable functions from the top of a script without digging through the code. In addition, when a disabled function is called, mafia will print a line informing you of this fact, while not acting on it. Important considerations:

  1. Mafia cannot differentiate between scripts that call functions of the same name. If function "foo" is disabled from script one, it will still be disabled when you run script two, unless you enable "foo" or restart mafia.
  2. Remember that CLI commands will be disabled if they have the same name (or can be disabled deliberately with this function).
  3. A disabled function still returns a value - the default value for its declared return type (false, 0, "", $item[none], an empty map, etc.). If a disabled function is incorporated into a condition (eg. "if(disabled_function())" ), then mafia will not just skip the entire conditional - execution will continue as normal, based on that default value.
  4. Using "all" as the string parameter will disable all ASH and CLI functions with the exception of enable and disable. Therefore, to re-enable all functions, you must type "enable all" into the CLI - ASH enable("all") would technically work, but at that point you'd have no way of invoking a script that contains it.
  5. disable() and enable() cannot be individually disabled using disable(), either.

 

Code Samples

This mini scriptlet generates a map that is outputted to a data file. In testing you might not want to do this every time, so you can disable map_to_file().

disable("map_to_file");

See Also

enable()