Raised This Month: $51 Target: $400
 12% 

WTF is dat error how do i fix?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 07-28-2015 , 06:42   WTF is dat error how do i fix?
Reply With Quote #1

Hey, I've wrote this simple lines
PHP Code:
new String:arg1[32];
GetCmdArg(1arg1sizeof(arg1));
new 
target;
target FindTarget(clientarg1); 
I don't want "FindTarget Is not recommended", Let me use my methods.
I added target = FindTarget(client, arg1); In some of my actions and not after new target;

Compiling... Got this error: include/helpers.inc(155) : warning 219: local variable "target" shadows a variable at a preceding level

Can someone help?
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 07-28-2015 , 06:51   Re: WTF is dat error how do i fix?
Reply With Quote #2

change target to a different name. so something like new clienttarget; you can chose though.
__________________
versatile_bfg is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 07-28-2015 , 06:52   Re: WTF is dat error how do i fix?
Reply With Quote #3

Quote:
Originally Posted by versatile_bfg View Post
change target to a different name. so something like new clienttarget; you can chose though.
LOL Really? 600 Lines plugin(On Start) I need to change all XD
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 07-28-2015 , 10:30   Re: WTF is dat error how do i fix?
Reply With Quote #4

you're missing a brace or something, that shouldn't happen
Miu is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 07-28-2015 , 11:11   Re: WTF is dat error how do i fix?
Reply With Quote #5

Or maybe compile more frequently so you can catch and correct these errors earlier before they snowball to something bigger?
Potato Uno is offline
Marcus_Brown001
AlliedModders Donor
Join Date: Nov 2012
Location: Illinois, United States
Old 07-28-2015 , 21:37   Re: WTF is dat error how do i fix?
Reply With Quote #6

I've gotten that error before. For me, I had two variables inside overlapping blocks of code within the same scope. Find where specifically the two variables are overlapping, and rename one of them. If you have a giant plugin, that sucks but there is no other way around it.
Marcus_Brown001 is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 07-28-2015 , 21:47   Re: WTF is dat error how do i fix?
Reply With Quote #7

PHP Code:
new String:arg1[32];
GetCmdArg(1arg1sizeof(arg1));
new 
target FindTarget(clientarg1); 
headline is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 07-28-2015 , 22:17   Re: WTF is dat error how do i fix?
Reply With Quote #8

if that code is all in function scope of a well-formed .sp file, it's nonsensical to encounter that warning in helpers.inc and I'm guessing the compiler has some bug
Miu is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 07-28-2015 , 23:45   Re: WTF is dat error how do i fix?
Reply With Quote #9

Shouldn't be hard at all. 600 lines isn't that big. You only need to change the one variable to a different name.
__________________
versatile_bfg is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 07-29-2015 , 01:57   Re: WTF is dat error how do i fix?
Reply With Quote #10

Quote:
Originally Posted by Headline22 View Post
PHP Code:
new String:arg1[32];
GetCmdArg(1arg1sizeof(arg1));
new 
target FindTarget(clientarg1); 
That would not fix this problem.

The problem is that he is trying to declare an (assumedly) global variable named target when a variable called target is also included in FindTarget() (which is a stock, not a native.)

The solution is to NOT declare a global variable named target while using FindTarget() anywhere in your plugin.

If target is NOT being declared globally in your plugin, then we have another problem.

Quote:
Originally Posted by Miu View Post
if that code is all in function scope of a well-formed .sp file, it's nonsensical to encounter that warning in helpers.inc and I'm guessing the compiler has some bug
FindTarget() is a stock, not a native. This means that the code that constitutes FindTarget() is compiled into the plugin, meaning all of its variables and parameters are subject to the plugin's scope rules. FindTarget() has a parameter named target. Therefore, a plugin that uses FindTarget() cannot have a global variable named target.
__________________

Last edited by ddhoward; 07-29-2015 at 02:05.
ddhoward is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:03.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode