SA-MP Forums Archive
string warning - 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: string warning (/showthread.php?tid=317813)



string warning - SumX - 12.02.2012

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



Re: string warning - lorigio - 12.02.2012

It means string is already used before.
Example

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


Re: string warning - Konstantinos - 12.02.2012

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



Re: string warning - ReneG - 12.02.2012

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



Re: string warning - SumX - 12.02.2012

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



Re: string warning - lorigio - 12.02.2012

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


Re: string warning - ReneG - 12.02.2012

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.


Re: string warning - SumX - 12.02.2012

Ok,thank you!


Re: string warning - [ABK]Antonio - 13.02.2012

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.


Re: string warning - Tannz0rz - 13.02.2012

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