SA-MP Forums Archive
[Tutorial] Warning and error list [WITH FIX] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Warning and error list [WITH FIX] (/showthread.php?tid=274028)

Pages: 1 2


Warning and error list [WITH FIX] - Jochemd - 04.08.2011

Warning and Error List

by Jochemd


Warnings

- Loose Indentation
pawn Код:
public OnPlayerLeaveCheckpoint(playerid)
{
    SendClientMessage(playerid,-1,"You have left a checkpoint.");
        print("Someone left a checkpoint");
    return 1;
}
pawn Код:
public OnPlayerLeaveCheckpoint(playerid)
{
    SendClientMessage(playerid,-1,"You have left a checkpoint.");
    print("Someone left a checkpoint");
    return 1;
}
- Unreachable code
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;
}
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
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    /* if(vehicleid == 520)
    {
        if(playerid == 0)
        {
            /* if(ispassenger)
            {
                print("Ohai!");
                return 1;
            }
        }
    } */

    return 1;
}
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
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;
}
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'
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;
}
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
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;
}
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)
pawn Код:
#define PutPos(%1,%2,%3,%4); SetPlayerPos(%9,%2,%3,%4); // %9 is not defined here.
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'
pawn Код:
CMD:myname(playerid,params[])
{
    #pragma unused params
    GetPlayerName(playerid,Playername,sizeof(Playername));
    SendClientMessage(playerid,-1,Playername);
    return 1;
}
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'
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;
}
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
pawn Код:
CMD:parachute(playerid,params[])
{
    #pragma unused params
    GivePlayerWeapon(playerid,46,1);k
    SendClientMessage(playerid,-1,"You got a parachute");
    return 1;
}
pawn Код:
CMD:parachute(playerid,params[])
{
    #pragma unused params
    GivePlayerWeapon(playerid,46,1);
    SendClientMessage(playerid,-1,"You got a parachute");
    return 1;
}
Empty statement
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;
}
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
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;
}
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'

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


Re: Warning and error list [WITH FIX] - Famalamalam - 04.08.2011

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

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



Re: Warning and error list [WITH FIX] - Calgon - 04.08.2011

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


Re: Warning and error list [WITH FIX] - System64 - 04.08.2011

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


Re: Warning and error list [WITH FIX] - Jochemd - 04.08.2011

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'


Re: Warning and error list [WITH FIX] - Famalamalam - 04.08.2011

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


Re: Warning and error list [WITH FIX] - Jochemd - 04.08.2011

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.


Re: Warning and error list [WITH FIX] - [MG]Dimi - 04.08.2011

"Function is not implented"

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


Re: Warning and error list [WITH FIX] - Rock_Ro - 04.08.2011

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


Re: Warning and error list [WITH FIX] - Jochemd - 04.08.2011

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


Re: Warning and error list [WITH FIX] - Michael@Belgium - 04.08.2011

Jochemd ... this is good !


Re: Warning and error list [WITH FIX] - Jochemd - 04.08.2011

Thanks


Re: Warning and error list [WITH FIX] - Sew_Sumi - 04.08.2011

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


Re: Warning and error list [WITH FIX] - IstuntmanI - 04.08.2011

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.


Re: Warning and error list [WITH FIX] - Basicz - 08.08.2011

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.


Re: Warning and error list [WITH FIX] - Deviant96 - 10.08.2011

Wow this is good! Im going to bookmark this page


Re: Warning and error list [WITH FIX] - SmileyForCheat - 10.08.2011

Where Link For Download


Re: Warning and error list [WITH FIX] - Darnell - 10.08.2011

This fixed all my errors


Re: Warning and error list [WITH FIX] - Jochemd - 10.08.2011

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.


Re: Warning and error list [WITH FIX] - justsomeguy - 14.08.2011

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