Errors List
From SA-MP Wiki
| Revision as of 11:07, 5 May 2012 Vince (Talk | contribs) (h1 headings not to be used + added warning 211) ← Previous diff |
Revision as of 09:51, 15 July 2012 Smithy (Talk | contribs) Next diff → |
||
| Line 11: | Line 11: | ||
| For example:<br/> | For example:<br/> | ||
| hello.pwn(3) : error 001: expected token: ";", but found "{" | 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.<br/><br/> | + | <b>Note:</b> The error may be on the line ABOVE the line that is shown, since the compiler cannot always establish an error before having analyzed the complete expression.<br/><br/> |
| == Error categories == | == Error categories == | ||
| Line 31: | Line 31: | ||
| == Common Errors== | == Common Errors== | ||
| + | ===035: argument type mismatch (argument x)=== | ||
| + | An argument passed to a function is of the wrong 'type'. | ||
| + | For example, passing a string where you should be passing an integer. | ||
| + | |||
| + | Example: | ||
| + | error 035: argument type mismatch (argument 1) | ||
| + | <pawn> | ||
| + | Kick("playerid"); // We are passing a STRING, we should be passing an INTEGER | ||
| + | </pawn> | ||
| + | |||
| + | '''Fixed:''' | ||
| + | <pawn> | ||
| + | Kick(playerid); | ||
| + | </pawn> | ||
| + | |||
| ===001: expected token=== | ===001: expected token=== | ||
| A required token is missing. | A required token is missing. | ||
| Line 68: | Line 83: | ||
| '''Fixed:''' | '''Fixed:''' | ||
| - | <pawn> | ||
| <pawn> | <pawn> | ||
| main() | main() | ||
| Line 91: | Line 105: | ||
| ===211: possibly unintended assignment=== | ===211: possibly unintended assignment=== | ||
| - | The assignment operator (=) was found in an if-statement, instead of the equality operator (<nowiki>==</nowiki>). If the assignment is intended, the expression must be wrapped in double parentheses. Exdample: | + | The assignment operator (=) was found in an if-statement, instead of the equality operator (<nowiki>==</nowiki>). If the assignment is intended, the expression must be wrapped in parentheses. Example: |
| <pawn> | <pawn> | ||
| Line 120: | Line 134: | ||
| </pawn> | </pawn> | ||
| - | Indentation means to push text along from the left of the page. This is used in pawn to make code easier to read. | + | Indentation means to push (indent) text along from the left of the page (by pressing the TAB key). This is common practise in programming to make code easier to read. |
| [[Category:Documentation]] | [[Category:Documentation]] | ||
| [[Category:Scripting]] | [[Category:Scripting]] | ||
Revision as of 09:51, 15 July 2012
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 error may be on the line ABOVE the line that is shown, 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
035: argument type mismatch (argument x)
An argument passed to a function is of the wrong 'type'. For example, passing a string where you should be passing an integer.
Example:
error 035: argument type mismatch (argument 1)
Kick("playerid"); // We are passing a STRING, we should be passing an INTEGER
Fixed:
Kick(playerid);
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:
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 parentheses. Example:
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 (indent) text along from the left of the page (by pressing the TAB key). This is common practise in programming to make code easier to read.
