Errors List

From SA-MP Wiki

Revision as of 11:07, 5 May 2012; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

Contents

General Pawn Error List

This pages contains the most common errors and warnings produced by the pawn compiler when creating SA:MP scripts.

When the compiler finds an error in a file, it outputs a message giving, in this order:
• the name of the file
• the line number were the compiler detected the error between parentheses, directly behind the filename
• the error class (“error”, “fatal error” or “warning”)
• an error number
• a descriptive error message

For example:

hello.pwn(3) : error 001: expected token: ";", but found "{"

Note: the line number given by the compiler may specify a position behind the actual error, since the compiler cannot always establish an error before having analyzed the complete expression.

Error categories

Errors are separated into three classes:

Errors

  • Describe situations where the compiler is unable to generate appropriate code.
  • Errors messages are numbered from 1 to 99.

Fatal errors

  • Fatal errors describe errors from which the compiler cannot recover.
  • Parsing is aborted.
  • Fatal error messages are numbered from 100 to 199.

Warnings

  • Warnings are displayed for unintended compiler assumptions and common mistakes.
  • Warning messages are numbered from 200 to 299.


Common Errors

001: expected token

A required token is missing.

Example:

error 001: expected token: ";", but found "return"
main()
{
    print("test") // This line is missing a semi-colon. That is the token it is expecting.
    return 1; // The error states that it found "return", this is this line it is referring to,
    // as it is after the point at which the missing token (in this case the semi-colon) should be.
}

002: only a single statement (or expression) can follow each “case”

Every case in a switch statement can hold exactly one statement.
To put multiple statements in a case, enclose these statements
between braces (which creates a compound statement).

Example:

error 002: only a single statement (or expression) can follow each "case"
main()
{
    switch(x)
    {
        case 0: print("hello"); print("hello");
    }
    return 1;
}

The above code also produces other warnings/errors:

error 002: only a single statement (or expression) can follow each "case"
warning 215: expression has no effect
error 010: invalid function or declaration

Fixed:

<pawn>
main()
{
    switch(x)
    {
        case 0:
        {
            print("hello");
            print("hello");
        }
    }
    return 1;
}



Common Warnings

211: possibly unintended assignment

The assignment operator (=) was found in an if-statement, instead of the equality operator (==). If the assignment is intended, the expression must be wrapped in double parentheses. Exdample:

if(a = 2) // warning
if(a == 2) // no warning
if((a = 2)) // no warning; the value 2 will be assigned to variable a and the expression will always return true.

217: loose indentation

The compiler will issue this warning if the code indentation is 'loose', example:

Good:

if(condition)
{
    action();
    result();
}

Bad:

if(condition)
{
    action();
  result();
}

Indentation means to push text along from the left of the page. This is used in pawn to make code easier to read.

Personal tools