[HELP] Fixing Warning
#1

I have this warning:
Код:
C:\DOCUME~1\Gustavo\Desktop\SAMP02~1.WIN\GAMEMO~1\WHRP.pwn(277) : warning 219: local variable "tmp" shadows a variable at a preceding level
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
This line (277) :
Код:
new tmp[256];
From this code:

pawn Код:
if(strcmp(cmd, "/givecash", true) == 0) {
      new tmp[256];
        tmp = strtok(cmdtext, idx);

        if(!strlen(tmp)) {
            SendClientMessage(playerid, COLOR_WHITE, "[SERVER] USAGE: /givecash [Playerid] [Amount]");
            return 1;
        }
        giveplayerid = strval(tmp);

        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp)) {
            SendClientMessage(playerid, COLOR_WHITE, "[SERVER] USAGE: /givecash [Playerid] [Amount]");
            return 1;
        }
        moneys = strval(tmp);

        //printf("givecash_command: %d %d",giveplayerid,moneys);


        if (IsPlayerConnected(giveplayerid)) {
            GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
            GetPlayerName(playerid, sendername, sizeof(sendername));
            playermoney = GetPlayerMoney(playerid);
            if (moneys > 0 && playermoney >= moneys) {
                GivePlayerMoney(playerid, (0 - moneys));
                GivePlayerMoney(giveplayerid, moneys);
                format(string, sizeof(string), "[SERVER] You have sent %s(player: %d), $%d.", giveplayer,giveplayerid, moneys);
                SendClientMessage(playerid, COLOR_YELLOW, string);
                format(string, sizeof(string), "[SERVER] You have recieved $%d from %s(player: %d).", moneys, sendername, playerid);
                SendClientMessage(giveplayerid, COLOR_YELLOW, string);
                printf("[SERVER] %s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid);
            }
            else {
                SendClientMessage(playerid, COLOR_YELLOW, "[SERVER] Invalid transaction amount.");
            }
        }
        else
        {
            format(string, sizeof(string), "[SERVER] %d is not an active player.", giveplayerid);
            SendClientMessage(playerid, COLOR_YELLOW, string);
        }
        return 1;
}
When I remove it, the warning stops to appear, but if I remove it, something will stop to function?
That's my question, cuz I can't test it.
Reply
#2

Try
pawn Код:
new tmp[128];
I dont know tmp's but I know that 128 is a variable that you can use more than once.
Reply
#3

Try
Код:
new tmp[128];
EDIT:LOL, almost the same reply...
Reply
#4

:/ now 2 errors, I will keep 256. Any more suggestions?
Reply
#5

This line (277) :
Код:
new tmp[256];
remove it completly.
Reply
#6

No, keep
Код:
new tmp[128];
and post here that errors you got now.
Reply
#7

Quote:
Originally Posted by [ToX
Justice ]
No, keep
Код:
new tmp[128];
and post here that errors you got now.
\
what the hell... stop saying bullshit, "128 is a variable you can use more than once" --- what the hell is this bullshit?

you already created a new tmp[256]; on top of the OnPlayerCommandText, so just delete the line you gave in the begginning
Reply
#8

Try not to be too heavy handed OmeRinG, when people don't understand string sizes point them towards Y-Less's topic that explains it all.

@ Post starter - When you get an error message, try to read what it actually says, they're usually quite descriptive. The error also gives you an error code, which is most likely listed in pawn-lang.pdf. I did the searching for you in this istance, and this is what it says for 219:

Quote:

A local variable has the same name as a global variable, a function, a function argument, or a local variable at a lower precedence level. This is called “shadowing”, as the new local variable makes the previously defined function or variable inaccessible.

This basically means outside a function/callback (lower precedence level) you defined tmp, and now at a higher level you're defining it again. To remove this error you simply need to give tmp a new name, or get rid of it and use the old definition..

The Scripting Discussion thread should be your last port of call, not the first place to run to whenever you see a compile error.
Reply
#9

Easy said Aka Bottom line.

Start making up some other names like...

pawn Код:
new idx[128];
new str[128];
etc etc etc...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)