string warning
#1

Hey,what's wrong here? i've searched it on ******,i've deleted the new string,renamed,but,the same problem."local variable "string" shadows a variable at a preceding level"; that line is this one,new string[1024]
pawn Код:
if(strcmp(cmd, "/vhelp", true) == 0)
    {
        new string[1024];

        if(PlayerInfo[playerid][pVIP] >= 1)return SendClientMessage(playerid, red, "You must have a V.I.P. Account to use this command! ");
        {
            strcat( string, "{FFD700}/vhelp\t\t\t{FFD700}/vrespawn\n" );
            strcat( string, "{FFD700}/vips\t\t\t{FFD700}/vgoto\n" );
            strcat( string, "{FFD700}/vnos\t\t\t{FFD700}/vgethere\n" );
            strcat( string, "{FFD700}/sultantune\t\t{FFD700}/vweapons\n" );
            strcat( string, "{FFD700}/jestertune\t\t{FFD700}/vammo\n" );
            strcat( string, "{FFD700}/elegytune\t\t{FFD700}/vclub\n" );
            strcat( string, "{FFD700}/othertune\n" );
            strcat( string, "{FFD700}Use '/vc' in front of text.This is the V.I.P. chat." );
            ShowPlayerDialog( playerid, VIPCMDS, DIALOG_STYLE_MSGBOX, "V.I.P. Commands:", string, "Quit", "" );
        }
        return 1;
    }
Reply
#2

It means string is already used before.
Example

new string[1024];
public example()
{
new string[1024]; <-- error
}
Reply
#3

That happens because you have already defined it.
An example to understand what I mean.
pawn Код:
public OnPlayerCommandText( playerid, cmdtext[ ] )
{
    new string[ 128 ]; // 1st string

    if(strcmp(cmd, "/vhelp", true) == 0)
    {
        new string[1024]; //2nd string

        if(PlayerInfo[playerid][pVIP] >= 1)return SendClientMessage(playerid, red, "You must have a V.I.P. Account to use this command! ");
        {
            strcat( string, "{FFD700}/vhelp\t\t\t{FFD700}/vrespawn\n" );
            strcat( string, "{FFD700}/vips\t\t\t{FFD700}/vgoto\n" );
            strcat( string, "{FFD700}/vnos\t\t\t{FFD700}/vgethere\n" );
            strcat( string, "{FFD700}/sultantune\t\t{FFD700}/vweapons\n" );
            strcat( string, "{FFD700}/jestertune\t\t{FFD700}/vammo\n" );
            strcat( string, "{FFD700}/elegytune\t\t{FFD700}/vclub\n" );
            strcat( string, "{FFD700}/othertune\n" );
            strcat( string, "{FFD700}Use '/vc' in front of text.This is the V.I.P. chat." );
            ShowPlayerDialog( playerid, VIPCMDS, DIALOG_STYLE_MSGBOX, "V.I.P. Commands:", string, "Quit", "" );
        }
        return 1;
    }
    return 0;
}
// Result: local variable "string" shadows a variable at a preceding level
Reply
#4

Holy shit. Don't use
pawn Код:
string[1024]
Use
pawn Код:
string[128]
Reply
#5

SOLVED,it's right?... i've compiled it and i dont have any warnings,errors
pawn Код:
if(strcmp(cmd, "/vhelp", true) == 0)
    {
        new GMstring[128];

        if(PlayerInfo[playerid][pVIP] >= 1)return SendClientMessage(playerid, red, "You must have a V.I.P. Account to use this command! ");
        {
            strcat( GMstring, "{FFD700}/vhelp\t\t\t{FFD700}/vrespawn\n" );
            strcat( GMstring, "{FFD700}/vips\t\t\t{FFD700}/vgoto\n" );
            strcat( GMstring, "{FFD700}/vnos\t\t\t{FFD700}/vgethere\n" );
            strcat( GMstring, "{FFD700}/sultantune\t\t{FFD700}/vweapons\n" );
            strcat( GMstring, "{FFD700}/jestertune\t\t{FFD700}/vammo\n" );
            strcat( GMstring, "{FFD700}/elegytune\t\t{FFD700}/vclub\n" );
            strcat( GMstring, "{FFD700}/othertune\n" );
            strcat( GMstring, "{FFD700}Use '/vc' in front of text.This is the V.I.P. chat." );
            ShowPlayerDialog( playerid, VIPCMDS, DIALOG_STYLE_MSGBOX, "V.I.P. Commands:", string, "Quit", "" );
        }
        return 1;
    }
Reply
#6

Quote:
Originally Posted by SumX
Посмотреть сообщение
SOLVED,it's right?... i've compiled it and i dont have any warnings,errors
pawn Код:
if(strcmp(cmd, "/vhelp", true) == 0)
    {
        new GMstring[128];

        if(PlayerInfo[playerid][pVIP] >= 1)return SendClientMessage(playerid, red, "You must have a V.I.P. Account to use this command! ");
        {
            strcat( GMstring, "{FFD700}/vhelp\t\t\t{FFD700}/vrespawn\n" );
            strcat( GMstring, "{FFD700}/vips\t\t\t{FFD700}/vgoto\n" );
            strcat( GMstring, "{FFD700}/vnos\t\t\t{FFD700}/vgethere\n" );
            strcat( GMstring, "{FFD700}/sultantune\t\t{FFD700}/vweapons\n" );
            strcat( GMstring, "{FFD700}/jestertune\t\t{FFD700}/vammo\n" );
            strcat( GMstring, "{FFD700}/elegytune\t\t{FFD700}/vclub\n" );
            strcat( GMstring, "{FFD700}/othertune\n" );
            strcat( GMstring, "{FFD700}Use '/vc' in front of text.This is the V.I.P. chat." );
            ShowPlayerDialog( playerid, VIPCMDS, DIALOG_STYLE_MSGBOX, "V.I.P. Commands:", string, "Quit", "" );
        }
        return 1;
    }
Yes it is
Reply
#7

Quote:
Originally Posted by SumX
Посмотреть сообщение
SOLVED,it's right?... i've compiled it and i dont have any warnings,errors
pawn Код:
if(strcmp(cmd, "/vhelp", true) == 0)
    {
        new GMstring[128];

        if(PlayerInfo[playerid][pVIP] >= 1)return SendClientMessage(playerid, red, "You must have a V.I.P. Account to use this command! ");
        {
            strcat( GMstring, "{FFD700}/vhelp\t\t\t{FFD700}/vrespawn\n" );
            strcat( GMstring, "{FFD700}/vips\t\t\t{FFD700}/vgoto\n" );
            strcat( GMstring, "{FFD700}/vnos\t\t\t{FFD700}/vgethere\n" );
            strcat( GMstring, "{FFD700}/sultantune\t\t{FFD700}/vweapons\n" );
            strcat( GMstring, "{FFD700}/jestertune\t\t{FFD700}/vammo\n" );
            strcat( GMstring, "{FFD700}/elegytune\t\t{FFD700}/vclub\n" );
            strcat( GMstring, "{FFD700}/othertune\n" );
            strcat( GMstring, "{FFD700}Use '/vc' in front of text.This is the V.I.P. chat." );
            ShowPlayerDialog( playerid, VIPCMDS, DIALOG_STYLE_MSGBOX, "V.I.P. Commands:", string, "Quit", "" );
        }
        return 1;
    }
Only way to find out if it works is to test it out IG. Let us know how it goes.
Reply
#8

Ok,thank you!
Reply
#9

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Holy shit. Don't use
pawn Код:
string[1024]
Use
pawn Код:
string[128]
He needs more than 128, he's using strcat so the size is going to be greater than 128.
Reply
#10

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
He needs more than 128, he's using strcat so the size is going to be greater than 128.
strcat itself is irrelevant to the size of the array. Whether or not he requires 128 cells depends on how many characters he must store (if anything, the string itself is unnecessary).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)