[Tutorial] Warning and error list [WITH FIX]
#1

Warning and Error List

by Jochemd


Warnings

- Loose Indentation
  • Cause: You got an unindented script
pawn Код:
public OnPlayerLeaveCheckpoint(playerid)
{
    SendClientMessage(playerid,-1,"You have left a checkpoint.");
        print("Someone left a checkpoint");
    return 1;
}
  • Fix: Make sure your script is idented
pawn Код:
public OnPlayerLeaveCheckpoint(playerid)
{
    SendClientMessage(playerid,-1,"You have left a checkpoint.");
    print("Someone left a checkpoint");
    return 1;
}
- Unreachable code
  • Cause: The part of the script the compiler says isn't reachable in any way; the script is returned before it reaches there.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid == 520) // Just a random ID, unsure if it really exists
    {
        SendClientMessage(playerid,-1,"You have entered vehicle ID 520.");
        return 1;
    }
    else return 0;
    return 1;
}
  • Fix: Make sure the code can be reached. It shouldn't be fully returned.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(vehicleid == 520) // Just a random ID, unsure if it really exists
    {
        SendClientMessage(playerid,-1,"You have entered vehicle ID 520.");
        return 1
    }
    return 1;
}
- Nested comment
  • Cause: A very unimportant warning. You have commented something into a comment.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    /* if(vehicleid == 520)
    {
        if(playerid == 0)
        {
            /* if(ispassenger)
            {
                print("Ohai!");
                return 1;
            }
        }
    } */

    return 1;
}
  • Fix: Simply remove the second comment
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    /* if(vehicleid == 520)
    {
        if(playerid == 0)
        {
            if(ispassenger)
            {
                print("Ohai!");
                return 1;
            }
        }
    } */

    return 1;
}
- Number of arguments does not match definition
  • Cause: You got more or less arguments (couldn't say it in another way) than you actually got to have.
pawn Код:
CMD:centermap(playerid,params[])
{
    #pragma unused params
    SetPlayerPos(playerid,0.0,0.0,3.0,90.0); // We've put the angle here too 'by accident'
    SendClientMessage(playerid,-1,"You have been sent to the center of the map in Blue Berry.");
    return 1;
}
  • Fix: Look for the correct syntaxes for the function. SA-MP Wiki says SetPlayerPos only has 4 arguments; playerid, X, Y and Z. This means the angle shouldn't be in there
pawn Код:
CMD:centermap(playerid,params[])
{
    #pragma unused params
    SetPlayerPos(playerid,0.0,0.0,3.0);
    SetPlayerFacingAngle(playerid,90.0); // Correct is to put the angle into this function.
    SendClientMessage(playerid,-1,"You have been sent to the center of the map in Blue Berry.");
    return 1;
}
- Symbol is never used 'symbol'
  • Cause: You've created a new array, but used it nowhere.
pawn Код:
CMD:skydive(playerid,params[])
{
    #pragma unused params
    new Float:Pos[3],string[128];
    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
    SetPlayerPos(playerid,Pos[0],Pos[1],Pos[2] + 200);
    SendClientMessage(playerid,-1,"You have been sent high in the sky.");
    GivePlayerWeapon(playerid,46,1);
    return 1;
}
  • Fix: Simply remove the array, which fixes it most of the times.
pawn Код:
CMD:skydive(playerid,params[])
{
    #pragma unused params
    new Float:Pos[3];
    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
    SetPlayerPos(playerid,Pos[0],Pos[1],Pos[2] + 200);
    SendClientMessage(playerid,-1,"You have been sent high in the sky.");
    GivePlayerWeapon(playerid,46,1);
    return 1;
}
- Tag mismatch
  • Cause: You've assigned the wrong label to an array.
pawn Код:
CMD:mypos(playerid,params[])
{
    #pragma unused params
    new Pos[3]; //  As you see the Pos array doesn't have the 'Float' label
    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
    printf("Your position: X: %f || Y: %f || Z: %f",Pos[0],Pos[1],Pos[2]);
    return 1;
}
  • Fix: Find the right label; in case of TextDraws ':Text', in case of 3D labels ':Text3D', and more.
pawn Код:
CMD:mypos(playerid,params[])
{
    #pragma unused params
    new Float:Pos[3]; //  Now it has the label, it is all right.
    GetPlayerPos(playerid,Pos[0],Pos[1],Pos[2]);
    printf("Your position: X: %f || Y: %f || Z: %f",Pos[0],Pos[1],Pos[2]);
    return 1;
}
- Unknown parameter in substitution (suggested by iggy1)
  • Cause: You've used a parameter in a define which is unknown.
pawn Код:
#define PutPos(%1,%2,%3,%4); SetPlayerPos(%9,%2,%3,%4); // %9 is not defined here.
  • Fix: Use the right parameters, and make sure they're defined before.
pawn Код:
#define PutPos(%1,%2,%3,%4); SetPlayerPos(%1,%2,%3,%4);
There are surely a lot of more warnings. Please give your suggestion which I should add!


Errors
- Undefined symbol 'symbol'
  • Cause: The opposite of 'symbol is never used'. You are using a symbol somewhere which you haven't created.
pawn Код:
CMD:myname(playerid,params[])
{
    #pragma unused params
    GetPlayerName(playerid,Playername,sizeof(Playername));
    SendClientMessage(playerid,-1,Playername);
    return 1;
}
  • Fix: Create the array you're using.
pawn Код:
CMD:myname(playerid,params[])
{
    #pragma unused params
    new Playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,Playername,sizeof(Playername));
    SendClientMessage(playerid,-1,Playername);
    return 1;
}
- Symbol already defined 'symbol'
  • Cause: You've created a symbol twice.
pawn Код:
CMD:myname(playerid,params[])
{
        new Playername[MAX_PLAYER_NAME];
    #pragma unused params
        new Playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,Playername,sizeof(Playername));
    SendClientMessage(playerid,-1,Playername);
    return 1;
}
  • Fix: Remove one of the two symbols you made.
pawn Код:
CMD:myname(playerid,params[])
{
    #pragma unused params
    new Playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid,Playername,sizeof(Playername));
    SendClientMessage(playerid,-1,Playername);
    return 1;
}
- Expression has no effect
  • Cause: Not sure about this one. I think it's caused by invalid symbols on places where they shouldn't be.
pawn Код:
CMD:parachute(playerid,params[])
{
    #pragma unused params
    GivePlayerWeapon(playerid,46,1);k
    SendClientMessage(playerid,-1,"You got a parachute");
    return 1;
}
  • Fix: Just remove that k.
pawn Код:
CMD:parachute(playerid,params[])
{
    #pragma unused params
    GivePlayerWeapon(playerid,46,1);
    SendClientMessage(playerid,-1,"You got a parachute");
    return 1;
}
Empty statement
  • Cause: You got double tokens, such as ;;.
pawn Код:
CMD:parachute(playerid,params[])
{
    #pragma unused params
    GivePlayerWeapon(playerid,46,1);; // This will give empty statement
    SendClientMessage(playerid,-1,"You got a parachute");
    return 1;
}
  • Fix: Find the double letter and remove it.
pawn Код:
CMD:parachute(playerid,params[])
{
    #pragma unused params
    GivePlayerWeapon(playerid,46,1); // This will give no errors.
    SendClientMessage(playerid,-1,"You got a parachute");
    return 1;
}
Function "function" is not implemented
  • First cause: You've used a function which isn't known by the compiler.
  • Second cause: If you get 26 errors, while a couple of them are this error, you've forgot to close a function with a bracket.
pawn Код:
CMD:stats(playerid,params[])
{
    SendFormatMessage(playerid,-1,"Cash: %d ... Score: %d",GetPlayerMoney(playerid),GetPlayerScore(playerid)); // We haven't added the stock in the function
    return 1;
}
  • First fix: Add the missing function in the script.
  • Second fix: Find the missing bracket and add it.
pawn Код:
new str[128];
#define SendFormatMessage(%0,%1,%2,%3) format(str, sizeof(str),%2,%3) && SendClientMessage(%0, %1, str)
[Fatal Error]- Cannot read from file 'file'
  • Cause:You have put on top of script '#include <file>' but the file does not exist in the folder '/pawno/includes'.
  • Fix: Put the file in the includes folder of pawno or remove the include line. This may cause problems with your script, so it's better to use the first solution.


Suggestions can be PMed to me.

Quote:
Originally Posted by Unsure Error List
  • Expression has no effect
  • Invalid function or declaration
I'd appreciate if you could PM me with what it means.

Hope this will help much people,

Jochem
Reply
#2

pawn Код:
error 036: empty statement
Example:

pawn Код:
SetPlayerInterior(playerid, 3);; // Notice extra semi-colon.
Reply
#3

This isn't advanced and would be a tutorial if anything.
Reply
#4

damn I wanted to make something like this
very nice, if I remember some error/warning I'll tell it!
Reply
#5

Quote:
Originally Posted by Calg00ne
Посмотреть сообщение
This isn't advanced and would be a tutorial if anything.
Thought the same while I was writing the titel. It's not a tutorial too. Well yeah, it is if you only look to 'how to fix it' but for now it's only an 'other'
Reply
#6

error 028: invalid subscript (not an array or too many subscripts): "symbol"
Reply
#7

Quote:
Originally Posted by Famalamalam
Посмотреть сообщение
error 028: invalid subscript (not an array or too many subscripts): "player1"
I'll write that for my next list.
Reply
#8

"Function is not implented"

Explanation: Forgot to close with "}" at previous callback, or something like that.
Reply
#9

If you use zcmd you don't need to use #pragma unused params
Reply
#10

Quote:
Originally Posted by Rock_Ro
Посмотреть сообщение
If you use zcmd you don't need to use #pragma unused params
Probably, I've learned in DCMD
Reply
#11

Jochemd ... this is good !
Reply
#12

Thanks
Reply
#13

Hell yea, + Rep for you, and I can't... *Grrrr*
Reply
#14

Change

Quote:
- Unreachable code
  • Cause: The part of the script the compiler says isn't reachable in any way; the script is returned before it reaches there.
Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vehicleid == 520) // Just a random ID, unsure if it really exists
	{
		SendClientMessage(playerid,-1,"You have entered vehicle ID 520.");
		return 1
	}
	else return 0;
	return 1;
}
  • Fix: Make sure the code can be reached. It shouldn't be fully returned.
Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vehicleid == 520) // Just a random ID, unsure if it really exists
	{
		SendClientMessage(playerid,-1,"You have entered vehicle ID 520.");
		return 1
	}
	return 1;
}
To
Quote:
- Unreachable code
  • Cause: The part of the script the compiler says isn't reachable in any way; the script is returned before it reaches there.
Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vehicleid == 520) // Just a random ID, unsure if it really exists
	{
		SendClientMessage(playerid,-1,"You have entered vehicle ID 520.");
		return 1;
	}
	else return 0;
	return 1;
}
  • Fix: Make sure the code can be reached. It shouldn't be fully returned.
Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vehicleid == 520) // Just a random ID, unsure if it really exists
	{
		SendClientMessage(playerid,-1,"You have entered vehicle ID 520.");
		return 1;
	}
	return 1;
}
There are much more warnings and errors ... anyway, nice tutorial.
Reply
#15

I usually did this to fix Unreachable Code ( AFAIK )
Code:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if ( vehicleid == 520 ) // Just a random ID, unsure if it really exists
    {
        SendClientMessage( playerid, -1, "You have entered vehicle ID 520." );
        return 1;
    }

    else if ( vehicleid != 520 ) 
        return 0;

    return 1;
}
Dunno, but as far as I remember I did that to fix Unreachable Code :P

Great list but,

Variable basicz shadows at a preceding level ( something like this ), please add it.
Reply
#16

Wow this is good! Im going to bookmark this page
Reply
#17

Where Link For Download
Reply
#18

This fixed all my errors
Reply
#19

Quote:
Originally Posted by SmileyForCheat
View Post
Where Link For Download
You can't download this... If you want it try copying just everything

Updating now.
Reply
#20

Argument mismatch(argument 2).
Code:
SendClientMessage(playerid, "Hi", COLOR_WHITE);
Fix:
Code:
SendClientMessage(playerid, COLOR_WHITE, "Hi);
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)