AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [TUT] Compiling errors (https://forums.alliedmods.net/showthread.php?t=87810)

minimiller 03-16-2009 16:30

[TUT] Compiling errors
 
A friend messaged me on steam the other day, asking me to help him debug his plugin. I asked whether he knew how to read the error and warning messages to which he replied "no". As of 16/03/2009, i dont think there is a tutorial to read these messages so i thought i would create 1
Note:
This is mainly for newbie scripters, as im guessing alot of intermediate / advanced scripters allready know about these error messages

The error messages of doom
Below is an example of an error message when trying to compile.
Quote:

C:\Users\Stu\Desktop\other\Stu's plugins\b_rush.sma(107) : error 035: argument type mismatch (argument 2)
Now lets break this error message down into smaller chunks

1) "C:\Users\Stu\Desktop\other\Stu's plugins\b_rush.sma"
This is where the source code of the plugin is saved. In my case, it is held in a folder on my desktop called "Stu's Plugins". It might be a good idea to create a folder on your desktop to keep all your plugins neat and tidy. Another good place to house plugins would be "C:/Program Files/Pawn Studio/Plugins", or "C:/Program Files/AMXMODX/Plugins"

2) "(107)"
(1/3 Main parts that you need to know)
The number within the brackets is what line the error/warning has been found. In our case, its occouring on line 107. With most good IDE's (Pawn Studio, AMXX Studio, etc.) the line numbers are printed down the left hand side to make it easier to find. If you're useing notepad or similar, there may be a keyboard shortcut E.g. Ctrl+H to goto a specific line number

3) "error 035:"
This is the error code. Im not entirely sure if there is a list of pawn error codes, so ill probably steal the 2nd post and make a list of them there. Allthough this error code is not nesseserily needed, it might be worth noting it down and how you fixed it for future reference.

4) "argument type mismatch"
(2/3 Main parts that you need to know)
In our case, an "argument type mismatch" is where the function "client_print" dosent have enough parameters.

5) "(argument 2)"
(3/3 Main parts that you need to know)
This shows precisely where the error is within the function

Break it down
So now we have broken down the error, we have a clearer view of where the error is and what is wrong
Part 1/3 shows that the error is on line 107
If we find our line 107, we find this:
Code:

client_print(0, "Welcome to the server!");
2/3 shows that client_print dosent have enough arguments
3/3 shows that argument 2 is incorrect

What should it be?
Lets check funcwiki and see what the client_print function should be:
Quote:

Originally Posted by http://www.amxmodx.org/funcwiki.php?go=func&id=22
client_print - Sends a message to a player.
Syntax:

client_print ( index, type, const message[], ... ) Type:

Native Notes:

id is a player index from 1 to 32. If 0, the message will be sent to all players.

The type is one of three types:
print_chat - chat text
print_console - console message
print_notify - console in dev mode
print_center - center say

Locating the error
So we can see that client_print should have a minimum of 3 arguments. Our code has 2
So lets check where we went wrong

our "index" is set to "0"
This is fine (Will print to the server)

Our "type" is set to "Welcome to the server!"
This is not a type, because the funcwiki says that we need to use print_chat, print_console, print_notify, or print_center.

If we check number (5) of our error again, we see that the error was in "(argument 2)", so this would back up our assumption that the "type" was wrong

Fixing the error
So we can now go back to line 107 and change it to this:
Code:

client_print(0, print_center, "Welcome to the server!");
Recompile
Now lets re-compile and see what happens...
Oh look!
Quote:

Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2006 ITB CompuPhase, AMX Mod X Team

Header size: 944 bytes
Code size: 3796 bytes
Data size: 1364 bytes
Stack/heap size: 16384 bytes; max. usage is unknown, due to recursion
Total requirements: 22488 bytes
Done.

Compilation Time: 1.10 sec
Hope this tut helped you. Whether it did or not, it passed another 30 mins and now im off to play a mix =]
x

minimiller 03-16-2009 16:30

Re: [TUT] Compiling errors
 
Thanks to Stupok =]
Quote:

/*001*/ "expected token: \"%s\", but found \"%s\"\n",
/*002*/ "only a single statement (or expression) can follow each \"case\"\n",
/*003*/ "declaration of a local variable must appear in a compound block\n",
/*004*/ "function \"%s\" is not implemented\n",
/*005*/ "function may not have arguments\n",
/*006*/ "must be assigned to an array\n",
/*007*/ "operator cannot be redefined\n",
/*008*/ "must be a constant expression; assumed zero\n",
/*009*/ "invalid array size (negative or zero)\n",
/*010*/ "invalid function or declaration\n",
/*011*/ "invalid outside functions\n",
/*012*/ "invalid function call, not a valid address\n",
/*013*/ "no entry point (no public functions)\n",
/*014*/ "invalid statement; not in switch\n",
/*015*/ "\"default\" case must be the last case in switch statement\n",
/*016*/ "multiple defaults in \"switch\"\n",
/*017*/ "undefined symbol \"%s\"\n",
/*018*/ "initialization data exceeds declared size\n",
/*019*/ "not a label: \"%s\"\n",
/*020*/ "invalid symbol name \"%s\"\n",
/*021*/ "symbol already defined: \"%s\"\n",
/*022*/ "must be lvalue (non-constant)\n",
/*023*/ "array assignment must be simple assignment\n",
/*024*/ "\"break\" or \"continue\" is out of context\n",
/*025*/ "function heading differs from prototype\n",
/*026*/ "no matching \"#if...\"\n",
/*027*/ "invalid character constant\n",
/*028*/ "invalid subscript (not an array or too many subscripts): \"%s\"\n",
/*029*/ "invalid expression, assumed zero\n",
/*030*/ "compound statement not closed at the end of file\n",
/*031*/ "unknown directive\n",
/*032*/ "array index out of bounds (variable \"%s\")\n",
/*033*/ "array must be indexed (variable \"%s\")\n",
/*034*/ "argument does not have a default value (argument %d)\n",
/*035*/ "argument type mismatch (argument %d)\n",
/*036*/ "empty statement\n",
/*037*/ "invalid string (possibly non-terminated string)\n",
/*038*/ "extra characters on line\n",
/*039*/ "constant symbol has no size\n",
/*040*/ "duplicate \"case\" label (value %d)\n",
/*041*/ "invalid ellipsis, array size is not known\n",
/*042*/ "invalid combination of class specifiers\n",
/*043*/ "character constant exceeds range for packed string\n",
/*044*/ "positional parameters must precede all named parameters\n",
/*045*/ "too many function arguments\n",
/*046*/ "unknown array size (variable \"%s\")\n",
/*047*/ "array sizes do not match, or destination array is too small\n",
/*048*/ "array dimensions do not match\n",
/*049*/ "invalid line continuation\n",
/*050*/ "invalid range\n",
/*051*/ "invalid subscript, use \"[ ]\" operators on major dimensions\n",
/*052*/ "multi-dimensional arrays must be fully initialized\n",
/*053*/ "exceeding maximum number of dimensions\n",
/*054*/ "unmatched closing brace\n",
/*055*/ "start of function body without function header\n",
/*056*/ "arrays, local variables and function arguments cannot be public (variable \"%s\")\n",
/*057*/ "unfinished expression before compiler directive\n",
/*058*/ "duplicate argument; same argument is passed twice\n",
/*059*/ "function argument may not have a default value (variable \"%s\")\n",
/*060*/ "multiple \"#else\" directives between \"#if ... #endif\"\n",
/*061*/ "\"#elseif\" directive follows an \"#else\" directive\n",
/*062*/ "number of operands does not fit the operator\n",
/*063*/ "function result tag of operator \"%s\" must be \"%s\"\n",
/*064*/ "cannot change predefined operators\n",
/*065*/ "function argument may only have a single tag (argument %d)\n",
/*066*/ "function argument may not be a reference argument or an array (argument \"%s\")\n",
/*067*/ "variable cannot be both a reference and an array (variable \"%s\")\n",
/*068*/ "invalid rational number precision in #pragma\n",
/*069*/ "rational number format already defined\n",
/*070*/ "rational number support was not enabled\n",
/*071*/ "user-defined operator must be declared before use (function \"%s\")\n",
/*072*/ "\"sizeof\" operator is invalid on \"function\" symbols\n",
/*073*/ "function argument must be an array (argument \"%s\")\n",
/*074*/ "#define pattern must start with an alphabetic character\n",
/*075*/ "input line too long (after substitutions)\n",
/*076*/ "syntax error in the expression, or invalid function call\n",
/*077*/ "malformed UTF-8 encoding, or corrupted file: %s\n",
/*078*/ "function uses both \"return\" and \"return <value>\"\n",
/*079*/ "inconsistent return types (array & non-array)\n",
/*080*/ "unknown symbol, or not a constant symbol (symbol \"%s\")\n",
/*081*/ "cannot take a tag as a default value for an indexed array parameter (symbol \"%s\")\n",
/*082*/ "user-defined operators and native functions may not have states\n",
/*083*/ "a function may only belong to a single automaton (symbol \"%s\")\n",
/*084*/ "state conflict: one of the states is already assigned to another implementation (symbol \"%s\")\n",
/*085*/ "no states are defined for function \"%s\"\n",
/*086*/ "unknown automaton \"%s\"\n",
/*087*/ "unknown state \"%s\" for automaton \"%s\"\n",
/*088*/ "number of arguments does not match definition\n"

xPaw 03-16-2009 16:38

Re: [TUT] Compiling errors
 
PHP Code:

client_print(0print_centre"Welcome to the server!");
// -> :)
client_print(0print_center"Welcome to the server!"); 


minimiller 03-16-2009 16:44

Re: [TUT] Compiling errors
 
fixed =]

Emp` 03-16-2009 17:34

Re: [TUT] Compiling errors
 
Glad someone finally did it. I never got around to it. GJ.

MeRcyLeZZ 03-22-2009 20:33

Re: [TUT] Compiling errors
 
Nice tut, certainly helpful for those unfamiliar with compilers.

Quote:

Originally Posted by minimiller
In our case, an "argument type mismatch" is where the function "client_print" dosent have enough parameters.

Actually, the type mismatch in that case is because you are passing a string (array) when it expects a single cell for the 2nd parameter. The actual "you didn't pass enough parameters" error is: error 088: number of arguments does not match definition. Just letting you know...

stupok 03-23-2009 21:30

Re: [TUT] Compiling errors
 
Quote:

Originally Posted by minimiller (Post 782133)
Im not entirely sure if there is a list of pawn error codes

I found one! (posting them here might help to direct newbs to this post when they search ;)

from amxmodx-1.8.1\compiler\libpc300\sc5.scp

Code:

static char *errmsg[] = {
#ifdef SCPACK
/*001*/  "expected token: \"%s\", but found \"%s\"\n",
/*002*/  "only a single statement (or expression) can follow each \"case\"\n",
/*003*/  "declaration of a local variable must appear in a compound block\n",
/*004*/  "function \"%s\" is not implemented\n",
/*005*/  "function may not have arguments\n",
/*006*/  "must be assigned to an array\n",
/*007*/  "operator cannot be redefined\n",
/*008*/  "must be a constant expression; assumed zero\n",
/*009*/  "invalid array size (negative or zero)\n",
/*010*/  "invalid function or declaration\n",
/*011*/  "invalid outside functions\n",
/*012*/  "invalid function call, not a valid address\n",
/*013*/  "no entry point (no public functions)\n",
/*014*/  "invalid statement; not in switch\n",
/*015*/  "\"default\" case must be the last case in switch statement\n",
/*016*/  "multiple defaults in \"switch\"\n",
/*017*/  "undefined symbol \"%s\"\n",
/*018*/  "initialization data exceeds declared size\n",
/*019*/  "not a label: \"%s\"\n",
/*020*/  "invalid symbol name \"%s\"\n",
/*021*/  "symbol already defined: \"%s\"\n",
/*022*/  "must be lvalue (non-constant)\n",
/*023*/  "array assignment must be simple assignment\n",
/*024*/  "\"break\" or \"continue\" is out of context\n",
/*025*/  "function heading differs from prototype\n",
/*026*/  "no matching \"#if...\"\n",
/*027*/  "invalid character constant\n",
/*028*/  "invalid subscript (not an array or too many subscripts): \"%s\"\n",
/*029*/  "invalid expression, assumed zero\n",
/*030*/  "compound statement not closed at the end of file\n",
/*031*/  "unknown directive\n",
/*032*/  "array index out of bounds (variable \"%s\")\n",
/*033*/  "array must be indexed (variable \"%s\")\n",
/*034*/  "argument does not have a default value (argument %d)\n",
/*035*/  "argument type mismatch (argument %d)\n",
/*036*/  "empty statement\n",
/*037*/  "invalid string (possibly non-terminated string)\n",
/*038*/  "extra characters on line\n",
/*039*/  "constant symbol has no size\n",
/*040*/  "duplicate \"case\" label (value %d)\n",
/*041*/  "invalid ellipsis, array size is not known\n",
/*042*/  "invalid combination of class specifiers\n",
/*043*/  "character constant exceeds range for packed string\n",
/*044*/  "positional parameters must precede all named parameters\n",
/*045*/  "too many function arguments\n",
/*046*/  "unknown array size (variable \"%s\")\n",
/*047*/  "array sizes do not match, or destination array is too small\n",
/*048*/  "array dimensions do not match\n",
/*049*/  "invalid line continuation\n",
/*050*/  "invalid range\n",
/*051*/  "invalid subscript, use \"[ ]\" operators on major dimensions\n",
/*052*/  "multi-dimensional arrays must be fully initialized\n",
/*053*/  "exceeding maximum number of dimensions\n",
/*054*/  "unmatched closing brace\n",
/*055*/  "start of function body without function header\n",
/*056*/  "arrays, local variables and function arguments cannot be public (variable \"%s\")\n",
/*057*/  "unfinished expression before compiler directive\n",
/*058*/  "duplicate argument; same argument is passed twice\n",
/*059*/  "function argument may not have a default value (variable \"%s\")\n",
/*060*/  "multiple \"#else\" directives between \"#if ... #endif\"\n",
/*061*/  "\"#elseif\" directive follows an \"#else\" directive\n",
/*062*/  "number of operands does not fit the operator\n",
/*063*/  "function result tag of operator \"%s\" must be \"%s\"\n",
/*064*/  "cannot change predefined operators\n",
/*065*/  "function argument may only have a single tag (argument %d)\n",
/*066*/  "function argument may not be a reference argument or an array (argument \"%s\")\n",
/*067*/  "variable cannot be both a reference and an array (variable \"%s\")\n",
/*068*/  "invalid rational number precision in #pragma\n",
/*069*/  "rational number format already defined\n",
/*070*/  "rational number support was not enabled\n",
/*071*/  "user-defined operator must be declared before use (function \"%s\")\n",
/*072*/  "\"sizeof\" operator is invalid on \"function\" symbols\n",
/*073*/  "function argument must be an array (argument \"%s\")\n",
/*074*/  "#define pattern must start with an alphabetic character\n",
/*075*/  "input line too long (after substitutions)\n",
/*076*/  "syntax error in the expression, or invalid function call\n",
/*077*/  "malformed UTF-8 encoding, or corrupted file: %s\n",
/*078*/  "function uses both \"return\" and \"return <value>\"\n",
/*079*/  "inconsistent return types (array & non-array)\n",
/*080*/  "unknown symbol, or not a constant symbol (symbol \"%s\")\n",
/*081*/  "cannot take a tag as a default value for an indexed array parameter (symbol \"%s\")\n",
/*082*/  "user-defined operators and native functions may not have states\n",
/*083*/  "a function may only belong to a single automaton (symbol \"%s\")\n",
/*084*/  "state conflict: one of the states is already assigned to another implementation (symbol \"%s\")\n",
/*085*/  "no states are defined for function \"%s\"\n",
/*086*/  "unknown automaton \"%s\"\n",
/*087*/  "unknown state \"%s\" for automaton \"%s\"\n",
/*088*/  "number of arguments does not match definition\n"


minimiller 03-24-2009 05:15

Re: [TUT] Compiling errors
 
nice 1 dude
ill update 2nd post when i get home

MeRcyLeZZ 03-24-2009 23:42

Re: [TUT] Compiling errors
 
1 Attachment(s)
It should also be noted that the errors aren't always caused by what the compiler says it's causing them.

For instance, today while I was working on ZP I started getting lots of error 017: undefined symbol "xxxxxx" (screenshot attached to post). About half an hour later I found out it was caused by the following code:
Code:
fnGetSurvivors() {     new iSurvivors, id         for (id = 1; id <= g_maxplayers; id++)     {         if (is_user_alive(id) && g_survivor[id])             iSurvivor++     }         return iSurvivors; }
The highlighted line should read iSurvivors++ instead. After I fixed that, it compiled just fine.


And this is yet another reason why you should regularly backup your files...

minimiller 03-25-2009 06:43

Re: [TUT] Compiling errors
 
so technically, it was correct
ISurvivor wasnt defined
So it was just a minor typo


All times are GMT -4. The time now is 22:13.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.