SA-MP Forums Archive
xyz.pwn(22109) : warning 214: possibly a "const" array argument was intended: "string" - 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)
+--- Thread: xyz.pwn(22109) : warning 214: possibly a "const" array argument was intended: "string" (/showthread.php?tid=659921)



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

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;
}




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

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


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

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");




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

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.


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

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);

?


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

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);



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

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);

?


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

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.


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

thank you