xyz.pwn(22109) : warning 214: possibly a "const" array argument was intended: "string"
#1

Help pls...


I update pawn compiler, last version and i recived this warning


xyz.pwn(22109) : warning 214: possibly a "const" array argument was intended: "string"

22109:
Quote:
stock CheckName(playerid, string[])
{
if(strfind(string, ".", true) == 0) return Kick(playerid);
new numbers, lenght = strlen(string);
for(new i; i < lenght; i++)
{
if(string[i] >= '0' && string[i] <= '9') numbers ++;
}
if(numbers < 5) return 0;
else if(numbers < Kick(playerid);
else BanEx(playerid, "Invalid Name");
return 1;
}

Reply
#2

Code:
CheckName(playerid, const string[])
Any array that is never modified should be a constant.
Reply
#3

Quote:
Originally Posted by Calisthenics
View Post
Code:
CheckName(playerid, const string[])
Any array that is never modified should be a constant.
Thank you bro..

And this? thank you

warning 239: literal array/string passed to a non-const parameter
Quote:

if(PlayerInfo[playerid][pTeam] != 5) SetPlayerCriminal(killerid, "Unknown", "First Degree Murder", 1);

or
warning 239: literal array/string passed to a non-const parameter
Quote:

if(PlayerProfile[playerid]) cmd_profile(playerid, "0");

Reply
#4

The compiler does not like to pass a string directly with the latest version.

pawn Code:
static profile_params[] = "0";
if(PlayerProfile[playerid]) cmd_profile(playerid, profile_params);
Since the text in `SetPlayerCriminal` function can be used in other parts of the script, create constants globally.
Reply
#5

Quote:
Originally Posted by Calisthenics
View Post
The compiler does not like to pass a string directly with the latest version.

pawn Code:
static profile_params[] = "0";
if(PlayerProfile[playerid]) cmd_profile(playerid, profile_params);
Since the text in `SetPlayerCriminal` function can be used in other parts of the script, create constants globally.
It's ok??

BEFORE:
Quote:

forward SetPlayerCriminal(playerid, declare[], reason[], wanted);

AFTER:
Quote:

forward SetPlayerCriminal(playerid, const declare[], const reason[], wanted);

?
Reply
#6

The warning is not about expecting constant array but passing a literal value. Make a crime list that you can access anywhere.
pawn Code:
enum
{
    CRIME_UNKNOWN, // constant, its value is 0
    CRIME_FIRST_DEGREE_MURDER // constant, its value is 1
}

new const CrimeList[][] =
{
    "Unknown", // index 0
    "First Degree Murder" // index 1
};
pawn Code:
if(PlayerInfo[playerid][pTeam] != 5) SetPlayerCriminal(killerid, CrimeList[CRIME_UNKNOWN], CrimeList[CRIME_FIRST_DEGREE_MURDER ], 1);
Reply
#7

Quote:
Originally Posted by Calisthenics
View Post
The warning is not about expecting constant array but passing a literal value. Make a crime list that you can access anywhere.
pawn Code:
enum
{
    CRIME_UNKNOWN, // constant, its value is 0
    CRIME_FIRST_DEGREE_MURDER // constant, its value is 1
}

new const CrimeList[][] =
{
    "Unknown", // index 0
    "First Degree Murder" // index 1
};
pawn Code:
if(PlayerInfo[playerid][pTeam] != 5) SetPlayerCriminal(killerid, CrimeList[CRIME_UNKNOWN], CrimeList[CRIME_FIRST_DEGREE_MURDER ], 1);
ok. but
And if I put it as I said, is not it ok? I'm not receiving warning.

Like this:
BEFORE:
Quote:
Quote:

forward SetPlayerCriminal(playerid, declare[], reason[], wanted);

AFTER:
Quote:
Quote:

forward SetPlayerCriminal(playerid, const declare[], const reason[], wanted);

?
Reply
#8

I did not know the warning can be fixed this way too, thanks. Yes, it is okay and now that I look at your code and the warning, your solution makes even more sense.
Reply
#9

thank you
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)