Difference between revisions of "ASH Errors"

From Kolmafia
Jump to navigation Jump to search
imported>Slyz
imported>Heeheehee
(OCD alphabetizing, as per slyz's request.)
(7 intermediate revisions by 2 users not shown)
Line 7: Line 7:
  
 
{{CodeSample|
 
{{CodeSample|
description=Example:|
+
description=The zero-parameter form:|
 +
code=
 +
<syntaxhighlight>
 +
abort();
 +
</syntaxhighlight>}}
 +
will stop the execution and print: <span style="color:red">KoLmafia declares world peace.</span> 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.
 +
 
 +
{{CodeSample|
 +
description=The one-parameter form:|
 
code=
 
code=
 
<syntaxhighlight>
 
<syntaxhighlight>
Line 27: Line 35:
 
will cause this error: <span style="color:red">Expected ;, found print (test.ash, line 2)</span>
 
will cause this error: <span style="color:red">Expected ;, found print (test.ash, line 2)</span>
  
===Missing return value===
+
===Invalid field name===
  
The last line of a user-defined function has to be "return <value>;" (although the [[return]] command can be used before too).
+
This indicates that the record does not contain the field in question.
  
 
{{CodeSample|
 
{{CodeSample|
Line 35: Line 43:
 
code=
 
code=
 
<syntaxhighlight>
 
<syntaxhighlight>
int my_function( int a, int b ) {
+
record my_record {
    if ( a > b ) return a ;
+
  string a;
    else return b ;
+
  string b;
}
+
};
 +
 
 +
my_record [int] my_map;
 +
my_map[1].c = "hello";
 
</syntaxhighlight>}}
 
</syntaxhighlight>}}
will cause this error: <span style="color:red">Missing return value (test.ash, line 4)</span>
+
will cause this error: <span style="color:red">Invalid field name 'c' (test.ash, line 7)</span>
  
===Script parsing error===
+
===Main method must appear at top level===
  
This generally indicates a syntax problem, as in having an excess amount of braces.
+
This indicates that the script's main method is inside another method, for some reason. This is usually caused by a missing brace.
  
 
{{CodeSample|
 
{{CodeSample|
Line 50: Line 61:
 
code=
 
code=
 
<syntaxhighlight>
 
<syntaxhighlight>
put_shop(0 ,0 ,$item[wolf mask]);
+
void stuff() {
put_shop(0 ,0 ,$item[rave whistle]);
+
  // stuff happens here
put_shop(0 ,0 ,$item[giant needle]);
 
cli_execute ("undercut");
 
}
 
</syntaxhighlight>}}
 
will cause this error: <span style="color:red">Script parsing error (test.ash, line 5)</span>
 
  
===Variable is already defined===
+
void main() {
 
+
  stuff();
This generally indicates that you declare the same variable twice.
+
}
 
 
{{CodeSample|
 
description=Example:|
 
code=
 
<syntaxhighlight>
 
int Drops ;
 
int Meat ;
 
int Drops ;
 
 
</syntaxhighlight>}}
 
</syntaxhighlight>}}
will cause this error: <span style="color:red">Variable Drops is already defined (test.ash, line 3)</span>
+
will cause this error: <span style="color:red">main method must appear at top level (test.ash, line 6)</span>
  
===Main method must appear at top level===
+
===Missing return value===
  
This indicates that the script's main method is inside another method, for some reason. This is usually caused by a missing brace.
+
The last line of a user-defined function has to be "return <value>;" (although the [[Control_Structures#return|return]] command can be used before too).
  
 
{{CodeSample|
 
{{CodeSample|
Line 80: Line 78:
 
code=
 
code=
 
<syntaxhighlight>
 
<syntaxhighlight>
void stuff() {
+
int my_function( int a, int b ) {
  // stuff happens here
+
    if ( a > b ) return a ;
 
+
    else return b ;
void main() {
 
  stuff();
 
 
}
 
}
 
</syntaxhighlight>}}
 
</syntaxhighlight>}}
will cause this error: <span style="color:red">main method must appear at top level (test.ash, line 6)</span>
+
will cause this error: <span style="color:red">Missing return value (test.ash, line 4)</span>
  
 
===Record expected===
 
===Record expected===
Line 101: Line 97:
 
will cause this error: <span style="color:red">Record expected (test.ash, line 2)</span>
 
will cause this error: <span style="color:red">Record expected (test.ash, line 2)</span>
  
===Invalid field name===
+
===Record name is already defined===
  
This indicates that the record does not contain the field in question.
+
This indicates that the record name has already been defined, and so cannot be reused. The solution is to change the record name.
  
 
{{CodeSample|
 
{{CodeSample|
Line 109: Line 105:
 
code=
 
code=
 
<syntaxhighlight>
 
<syntaxhighlight>
record dblstr {
+
record str {
 
   string a;
 
   string a;
 
   string b;
 
   string b;
 
};
 
};
 
+
record str {
dblstr [int] map;
+
  int a;
map[1].c = "hello";
+
  int b;
 +
};
 
</syntaxhighlight>}}
 
</syntaxhighlight>}}
will cause this error: <span style="color:red">Invalid field name 'c' (test.ash, line 7)</span>
+
will cause this error: <span style="color:red">Record name 'str' is already defined (test.ash, line 5)</span>
  
 
===Reserved word cannot be a record name===
 
===Reserved word cannot be a record name===
Line 134: Line 131:
 
will cause this error: <span style="color:red">Reserved word 'string' cannot be a record name (test.ash, line 1)</span>
 
will cause this error: <span style="color:red">Reserved word 'string' cannot be a record name (test.ash, line 1)</span>
  
===Record name is already defined===
+
===Script parsing error===
 +
 
 +
This generally indicates a syntax problem, as in having an excess amount of braces.
 +
 
 +
{{CodeSample|
 +
description=Example:|
 +
code=
 +
<syntaxhighlight>
 +
put_shop(0 ,0 ,$item[wolf mask]);
 +
put_shop(0 ,0 ,$item[rave whistle]);
 +
put_shop(0 ,0 ,$item[giant needle]);
 +
cli_execute ("undercut");
 +
}
 +
</syntaxhighlight>}}
 +
will cause this error: <span style="color:red">Script parsing error (test.ash, line 5)</span>
 +
 
 +
===Variable 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.
+
This indicates that the same variable has been declared twice.
  
 
{{CodeSample|
 
{{CodeSample|
Line 142: Line 155:
 
code=
 
code=
 
<syntaxhighlight>
 
<syntaxhighlight>
record str {
+
int Drops ;
  string a;
+
int Meat ;
  string b;
+
int Drops = numeric_modifier("Item Drop");
};
 
record str {
 
  string a;
 
  string b;
 
};
 
 
</syntaxhighlight>}}
 
</syntaxhighlight>}}
will cause this error: <span style="color:red">Record name 'str' is already defined (test.ash, line 5)</span>
+
will cause this error: <span style="color:red">Variable Drops is already defined (test.ash, line 3)</span>
  
  
 
{{RFI|Obviously, a lot more info is needed here.}}
 
{{RFI|Obviously, a lot more info is needed here.}}

Revision as of 18:46, 18 April 2010

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...

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)

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)

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)

Reserved word cannot be a record name

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

Example:

record string {
   string a;
   string b;
};

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

Script parsing error

This generally indicates a syntax problem, as in having an excess amount of braces.

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.