SA-MP Forums Archive
local variable "object" shadows a variable at a preceding level - 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: local variable "object" shadows a variable at a preceding level (/showthread.php?tid=468797)



local variable "object" shadows a variable at a preceding level - James Bob - 10.10.2013

Well the title explains everything, I've put in my script a system where when the player dies they drop the weapon they're holding, and you use /pgun to pick it up..

Код:
local variable "object" shadows a variable at a preceding level



Re: local variable "object" shadows a variable at a preceding level - Konstantinos - 10.10.2013

You've declared it as a global and local variable.


Re: local variable "object" shadows a variable at a preceding level - James Bob - 10.10.2013

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
You've declared it as a global and local variable.
Wait what? Now I'm even more confused.


Re: local variable "object" shadows a variable at a preceding level - xVIP3Rx - 10.10.2013

You have another
pawn Код:
new object
at the top of the script, Changing the local one's name should fix it.


Re: local variable "object" shadows a variable at a preceding level - EiresJason - 10.10.2013

You have something like this:

pawn Код:
new object; //this is a global variable.
public OnPlayerText(playerid, text[])
{
    new object; //this is a local variable.
        //You can rename the local variable to fix this issue.
        //more code.
}

So:
public OnPlayerText(playerid, text[])
{
    new myobject; //this is a local variable.
        //You can rename the local variable to fix this issue.
        //more code.
}



Re: local variable "object" shadows a variable at a preceding level - Konstantinos - 10.10.2013

I'm going to give you the simplest example.

pawn Код:
#include < a_samp >

new
    sth // declared as global variable
;

main( ) { }

public OnGameModeInit( )
{
    new
        sth // declared as local variable
    ;
    // code
    return 1;
}



Re: local variable "object" shadows a variable at a preceding level - James Bob - 10.10.2013

Код:
C:\Documents and Settings\Ashley\Desktop\DSRP1\gamemodes\RZRP.pwn(96398) : error 017: undefined symbol "object"
C:\Documents and Settings\Ashley\Desktop\DSRP1\gamemodes\RZRP.pwn(96398) : warning 215: expression has no effect
C:\Documents and Settings\Ashley\Desktop\DSRP1\gamemodes\RZRP.pwn(96398) : error 001: expected token: ";", but found "]"
C:\Documents and Settings\Ashley\Desktop\DSRP1\gamemodes\RZRP.pwn(96398) : error 029: invalid expression, assumed zero
C:\Documents and Settings\Ashley\Desktop\DSRP1\gamemodes\RZRP.pwn(96398) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.



Re: local variable "object" shadows a variable at a preceding level - Konstantinos - 10.10.2013

I assume you deleted the global one and it's used in another callbacks too?


Re: local variable "object" shadows a variable at a preceding level - James Bob - 10.10.2013

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I assume you deleted the global one and it's used in another callbacks too?
The thing is tho, I don't find a local one.


Re: local variable "object" shadows a variable at a preceding level - xVIP3Rx - 10.10.2013

Try to put the global one again, Then compile and go to the line with error and rename it to something else ?