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



string - aboa - 30.07.2013

pawn Код:
C:\Users\gtfytgfy\Desktop\LSS-RP\gamemodes\LSS-RP.pwn(40948) : warning 219: local variable "string" shadows a variable at a preceding level
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Warning.
pawn Код:
if(strcmp(cmd, "/paycheck", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            new string[128];
            format(string, sizeof(string), "* You have played for %d minutes in the past hour.", PlayerInfo[playerid][pMinutes]);
            if(PlayerInfo[playerid][pMinutes] < 40) SendClientMessage(playerid, COLOR_LIGHTRED, string);
            else SendClientMessage(playerid, COLOR_LIME, string);
            format(string, sizeof(string), "* You need to play for at least 40 minutes every hour to recieve a paycheck.");
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
            return 1;
        }
        return 1;
    }



Re: string - DobbysGamertag - 30.07.2013

Means you have it declared as new in the same function. Or globally. Change the "string" accordingly otherwise, just try putting it as new at the start of OnPlayerCommandText after the "{ "


Re: string - antonio112 - 30.07.2013

Like DobbysGamertag mentioned, you already declared the 'string' variable as a global variable.

You have 2 options in this case:

1. You can change the 'string' name in your command.

2. You can just use the 'string' variable without 'recreating' it in your command.

Here are both cases:

1 - In this case, you need to change 'string' to something else, like below:
pawn Код:
if(strcmp(cmd, "/paycheck", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            new astring[128]; // We changed the string name from 'string' to 'astring'
            format(astring, sizeof(astring), "* You have played for %d minutes in the past hour.", PlayerInfo[playerid][pMinutes]);
            if(PlayerInfo[playerid][pMinutes] < 40) SendClientMessage(playerid, COLOR_LIGHTRED, astring);
            else SendClientMessage(playerid, COLOR_LIME, astring);
            format(string, sizeof(string), "* You need to play for at least 40 minutes every hour to recieve a paycheck.");
            SendClientMessage(playerid, COLOR_LIGHTBLUE, astring);
            return 1;
        }
        return 1;
    }
2 - You can just format the 'string' without creating it in your command, since it's already been created
pawn Код:
if(strcmp(cmd, "/paycheck", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            format(string, sizeof(string), "* You have played for %d minutes in the past hour.", PlayerInfo[playerid][pMinutes]);
            if(PlayerInfo[playerid][pMinutes] < 40) SendClientMessage(playerid, COLOR_LIGHTRED, string);
            else SendClientMessage(playerid, COLOR_LIME, string);
            format(string, sizeof(string), "* You need to play for at least 40 minutes every hour to recieve a paycheck.");
            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
            return 1;
        }
        return 1;
    }
Even though both cases should work, I recommend you to use case 1.

Regards,
Tony