Most Common Errors You Can Encounter Every Now and Then
- Devilicioux
Thanks to Antichristus, Black Rose, NiHiLaNTh, FlickeRr
As the title says .. I am going to place all the common errors that occur with the possible solution of that with example threads which have been buried into the sub forums despite of the perfect solution just because people dont care about searching before posting.Most of them just want the veteran title and just spam and post for post counts.
No matter how smart or how careful you are, errors are your constant companion. With practice, you will get slightly better at not making errors, and much, much better at finding and correcting them.
ERROR VS WARNING
Definition
First Of all, there is a HUGE difference between Error and Warning.. They are in no way similar or to be compared while we work on PAWN.
A Error means your code has a syntactic/semantic/runtime error that causes the compiler to give up. Source cannot be compiled. You must fix the error.We will get onto the examples in some time.
A Warning means the compiler suspects your program might crash or behave strangely but the syntax is correct. The warning suggests you rework the code to make the warning go away.
Example is the Indentation warning we newbies get
TYPE OF ERRORS
Type Of Errors
1. Syntax Errors
Definition
This is encountered when you are trying to interpret syntactically invalid code.
Example : Invalid Function Call.
2. Semantic Errors
Definition
These occur when your code is syntacticall correct but logically/semantically incorrect.
Eg : Dividing by Zero.
3. Runtime Errors
Definition
These occur at the runtime .Good Thing about them is your plugin tells you in error logs where the plugin had gone wrong/malfunctioned.
Example : Stack Errors, Index Out of bounds, Null Pointers etc.
One of the best thing about AMXX errors is When you get a error, it will show a full trace of the problem which eases out the pain of error solving by restricting it to the single line or a part of code where the error occurs.
Here goes the List of Errors (Click on Spoilers to get the description and solution):
RUNTIME ERRORS
[AMXX] Run time error 3: stack error
Error Info
Description : A stack error occures if the heapsize is full, this usually occures on to huge/many variables or any leak in your plugin.Your plugin(s) is(are) using too much memory. Solution : Depends on your source code.. Put your plugin in debug mode and use the error line number to fix up that error. Still Unable to fix up the error ? SEARCH then Post it on subforum if nt able to find similar error fix.. Dont Just Post.
index out of bounds = an invalid vector cell has been used that goes over the maximum value of it.
EX:
PHP Code:
new vector[20] // This means that you have 20 cellls and you can access them from 0 to 19
vector[0] // WIll work
vector[2] // Will work
vector[10] // Will work
vector[19] // Will work
vector[20] // Will show index out of bounds
vector[50] // Will show index out of bounds
vector[100] // Will show index out of bounds
[AMXX] Run time error 10: native error (native "cs_get_user_team")
Invalid player with a number > 0 means the player is not connected anymore when the native has been called. You should check if player is alive before.
[AMXX] Run time error 10: native error (native "menu_display")
Error Info
Description : Occurs When the menu is called after you have destroyed it. Solution : You don't need to always destroy the menu. Create the menus once, saves memory and runtime time.Don't use menu_destroy unlessyou are done with the menu completely.
Also..
Quote:
Originally Posted by Backstabnoob
That error is kind of a mystery, I'm not experiencing it myself but there are many people which do while doing nothing wrong.
[AMXX] Run time error 10: native error (native "OrpheuGetFunction")
Post a request in scripting subforum(If you dont know how to make them) for the updated signatures.
[AMXX] Run time error 11: divide
Error Info
Description : You are Dividing something by Zero. Solution : Exception handling is all you need.Write a check if the variable in the denominator doesnt get the value as 0.
[AMXX] Run time error 25: parameter error
Error Info
Quote:
Originally Posted by NiHiLaNTh
String formatted incorrectly - parameter PARAMETER_NUMBER
(total PARAMETER_COUNT)
It happens when you have formatted any string and have parameter count mismatch like in here:
If you're making a menu global, don't destroy it.Do everything like you always do, return when item == MENU_EXIT.Just don't use menu_destroy(iMenu); when you're using a global menu
Quote:
Originally Posted by Emp`
You use menu_destroy to free the resources for that menu. If you have a menu that will never change and can be accessed any time, then you can create a global to store the menu, and then never destroy it. (Note that the menu is destroyed at map change)
Quote:
Originally Posted by fysiks
If you have a global menu, you don't destroy it until plugin_end().
[HAMSANDWICH] Invalid HamHook handle
Error Info
Description : Self Explanatory. Solution : Did you even create a Ham Forward ?
Invalid multi-lingual line (file "cstrike/addons/amxmodx/data/lang/something.txt" line 1)
Error Info
Description : ML file not able to be read correctly by the plugin. Solution : You know how to solve it.. Check if the syntax of ML file is correct.
Description : Error Descriptive Enough Solution : Correct Number Of Parameters Demanded.
Invalid CVAR pointer
Error Info
Description : Error Descriptive Enough.Is the cvar you are calling correct ? Solution : Try to register the cvars before the events/forwards.Check if the cvar names you wrote at various places in source code are correct.
[HAMSANDWICH] Invalid entity *
Error Info
Description : Self Explanatory.Entity is invalid Solution : All you need to do is make sure it's valid with pev_valid or something.
Quote:
Originally Posted by Arkshine
Forwards are not set. You create the variables, but default value is 0, empty so. You are supposed to filled these variables with RegisterHam return value, otherwise how you can expect the module to know?
COMPILATION ERRORS
Error 002: only a single statement (or expression) can follow each "case"
Error Info
Description : Reason of the error can be you are not finished up with the plugin or missed out something in syntax of CASE.
Quote:
FIX YOUR SWITCH STATEMENTS.
Use Curly Braces appropriately.
A Simple Switch Statement goes like this.
PHP Code:
new team = get_user_team(player)
switch (team)
{
case TEAM_T: {//code... }
case TEAM_CT: { //code... }
case TEAM_SPECTATOR:{ //code... }
}
Quote:
It is always a good coding habit to use braces even for a single line statements
error 052 - multi-dimensional arrays must be fully initialized
Error Info
Description : Did you declare a multi dimensional array and operating on it as a 1-D array ? Solution : You know what you did wrong.Fix it.
We have a Awesome [INC] to work on Arrays by Emp` for you here(in case you are interested in learning ).. Here you go ..
☺ [INC]Arrays with N Dimensions by Emp`
☺ [Module] ArrayX by Twilight Suzuka
error 075: input line too long (after substitutions)
Error Info
Thanks to Black Rose for the nice explanation of why the error occurs and how to avoid this error HERE
Error 088: Number of arguments does not match to definition (line something)
Error Info
Description : You are not providing the correct number of arguments the function needs. Solution : Find out how many arguments the function actually needs and fix it.
Fatal error 100: cannot read from file: "something"
Error Info
Description : Missing Include file in the include Directory. Solution : You must compile it locally as it requires additional include files.
Warning 236: unknown parameter in substitution (incorrect #define pattern)
Error Info
Description : Occurs when compiler fails to substitute parameters correctly in a macro declared. Solution : You must compile it locally as it requires additional include files.
Undefined symbol "<any>"
Error Info
Description :
♥ Do you have all the necessary includes on the top of source code ?
♥ Have you defined all the variables ?
♥ Are you trying to pass id to a function Like Here ? Solution : Description is Self Explanatory.
Error: Initialization data exceeds declared size on line
Error Info
Description : Occurs when you provide data exceeding the size of the array declared. Solution : Upto you.. Increase the size of the array or Decrease the Data.
Best solution can be making the use of dynamic array. (Look in cellarray.inc)
Error: expected token: ";" but found "-identifier-"
Spoiler
Description : You missed out a semicolon somewhere. Solution : AMXX compile doesn't require a ; by default, you have a #pragma semicolon (or something) in your code that forces the source to requires it, just remove that and you don't have to worry about ; anymore.
WARNINGS
Tag mismatch
Warning Info
Description : If you attempt to mix tags in an expression, you will get the infamous (213) "Tag mismatch" warning from the compiler. Understand Better Here. Solution : Read the Link in Description above.
warning 217: loose indentation
Spoiler
Description:
Quote:
Originally Posted by Wilson [29th ID]
Loose Indentation is when you don't have your code set up into "paragraphs" correctly. It is not an error; it is a warning - usually it means you overlooked something.
Solution :
Quote:
Originally Posted by Hunter-Digital
It's best to actually learn to indent your code, it would be easier for you and everyone else to read it if it's nicely aligned and would in fact make it easier to debug your code.
Alternative Solution :
Quote:
Originally Posted by Kotel
#pragma tabsize 0
Warning 236: unknown parameter in substitution (incorrect #define pattern)
Warning Info
Description : Occurs when compiler fails to substitute parameters perfectly in a macro declared. Solution : You need to fix the Macro declaration.
Quote:
Avoid using complicated and ugly macros.Instead evaluate such expressions via stock or function with lesser complexity.
Warning 237 - recursive function name
Warning Info
Description : The specified function calls itself recursively.
Solution : Although this is valid in pawn, a self-call is often an error. Note that this warning is only generated when the pawn parser/compiler is set to “verbose” mode.
Reference #PawnGuide
I will keep improving and updating the Thread forever until this thread becomes a 1 stop heaven for coders not able to narrow out the errors they getting
** If you have something to Add up that i missed or something to correct what i wrote.. PM or comment for contribution Obviously you will get the credits
I hope this makes life of coders a little easier [Because i Like Orange ]
__________________
You keep bringing ANTICHRISTUS down .. He will rise again and kick asses !
This would be better placed in Code Snippets/ Tutorials. Its probably the best spot for people to read this
Maybe some moderator can decide and do the needful moving of the post.
I had no idea where to post this .. But this post will surely help a lot of coding newbies like me and other ppl in narrowing the details of errors usually encountered.
__________________
You keep bringing ANTICHRISTUS down .. He will rise again and kick asses !
I suggest you to change the thread title to something mentioning the main purpose of the thread. I mean, that many people will think these are compiling errors when see the titile, but they are actually error logs. So, put some "error log" in the title - to be maximum descriptive to the including inside.
I suggest you to change the thread title to something mentioning the main purpose of the thread. I mean, that many people will think these are compiling errors when see the titile, but they are actually error logs. So, put some "error log" in the title - to be maximum descriptive to the including inside.
He has both "run time" and compile errors. IMO they should not be called "error logs".