ASH Errors

From Kolmafia
Jump to navigation Jump to search

Errors happen. When they do, it helps to have some idea of what what wrong.

Abort

Whenever a script runs the abort() function, this error is generated.

The zero-parameter form:

abort();

will stop the execution and print: KoLmafia declares world peace. Note that this message may also appear as a result of pressing Esc in the Main Interface or hitting "stop now" in the Adventure tab.

The one-parameter form:

abort("Aborting script...");

will stop the execution and print: Aborting script...

Cannot return [datatype] from [datatype] function

This indicates that the return value does not match the function's type.

Example:

int stuff(){
   return "4";
}

will cause this error: Cannot return string value from int function (test.ash, line 2)

Similarly, for void functions:

void stuff(){
   return 4;
}

will cause this error: Cannot return a value from a void function (test.ash, line 2)

Encountered '[break|continue]' outside loop

This indicates that the control structure in question was not in a loop.

Example:

continue;

will cause this error: Encountered 'break' outside of loop (test.ash, line 1)

Expected

This generally indicates a syntax problem (missing ending semi-colon, unmatched braces, unmatched parenthesis etc...).

Example:

int a = 1
print(a);

will cause this error: Expected ;, found print (test.ash, line 2)

"if" requires a boolean conditional expression

This indicates that the condition inside an if statement is not a boolean.

Example:

if(42) {
   print("Don't panic.");
}

will cause this error: "if" requires a boolean conditional expression (test.ash, line 1)

Index type is not a primitive type

This indicates that the map's index is not a standard datatype (float, int, string, etc.).

Example:

record alpha{
   int a;
   int b;
};
int[alpha] map;

will cause this error: Index type 'alpha' is not a primitive type (test.ash, line 5)

Invalid field name

This indicates that the record does not contain the field in question.

Example:

record my_record {
   string a;
   string b;
};

my_record [int] my_map;
my_map[1].c = "hello";

will cause this error: Invalid field name 'c' (test.ash, line 7)

Note that this error may also be encountered when neglecting to name a field.

For instance:

record my_record {
   string;
};

will cause this error: Invalid field name ';' (test.ash, line 2)

Invalid type name

This indicates that the specified type is not recognized by Mafia.

Example:

int[fruit] map;

will cause this error: Invalid type name 'fruit' (test.ash, line 1)

Main method must appear at top level

This indicates that the script's main method is inside another method, for some reason. This is usually caused by a missing brace.

Example:

void stuff() {
   // stuff happens here

void main() {
   stuff();
}

will cause this error: main method must appear at top level (test.ash, line 6)

Missing return value

The last line of a user-defined function has to be "return <value>;" (although the return command can be used before too).

Example:

int my_function( int a, int b ) {	
    if ( a > b ) return a ;
    else return b ;
}

will cause this error: Missing return value (test.ash, line 4)

Record expected

This indicates that an unrecognized record was found. This often appears when you forget to append "()" to a function name.

Example:

print(4.to_string);

will cause this error: Record expected (test.ash, line 2)

Record name is already defined

This indicates that the record name has already been defined, and so cannot be reused. The solution is to change the record name.

Example:

record str {
   string a;
   string b;
};
record str {
   int a;
   int b;
};

will cause this error: Record name 'str' is already defined (test.ash, line 5)

Return needs [datatype] value

This indicates that the return value is void when the function is not.

Example:

int stuff() {
   return;
}

will cause this error: Return needs int value (test.ash, line 2)

Reserved word cannot be a [function|record|variable] name

This indicates that the desired name has been reserved, and so cannot be used. The solution is to use a different name.

An invalid name:

int float(float a) {
   return round(a);
}

will cause this error: Reserved word 'float' cannot be used as a function name (test.ash, line 1)

An interesting point to note is that ASH functions take precedent over identically named custom functions rather than throw an exception.

An invalid record name:

record string {
   string a;
   string b;
};

will cause this error: Reserved word 'string' cannot be a record name (test.ash, line 1)

An invalid variable name:

string item = "bottle of gin";

will cause this error: Reserved word 'item' cannot be a variable name (test.ash, line 1)

Script parsing error

This generally indicates a syntax problem, as in having an excess amount of braces or a variable/function/record name that starts with an invalid character.

Example:

put_shop(0 ,0 ,$item[wolf mask]);
put_shop(0 ,0 ,$item[rave whistle]);
put_shop(0 ,0 ,$item[giant needle]);
cli_execute ("undercut");
}

will cause this error: Script parsing error (test.ash, line 5)

Variable is already defined

This indicates that the same variable has been declared twice.

Example:

int Drops ;
int Meat ;
int Drops = numeric_modifier("Item Drop");

will cause this error: Variable Drops is already defined (test.ash, line 3)


Attention KoLmafia Experts!

We need your help; some details of this function's operation are unknown or unclear.

The following specific question has been raised:

  • Obviously, a lot more info is needed here.