SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 14/10/2009, 03:20 PM   #1
ғαιιοцт
High-roller
 
ғαιιοцт's Avatar
 
Join Date: Feb 2008
Posts: 1,428
Reputation: 188
Default local variable "KillsName" shadows a variable at a preceding level (weird)

I get these warnings:
Quote:
symbol already defined: "File"
local variable "Kills" shadows a variable at a preceding level
local variable "KillsName" shadows a variable at a preceding level
but I don't have them more then once defined on a level

how is it possible that I get this error?




code:

Code:
		if(!strcmp(cmd,"/read", true))
		{
			new File[64]= "ScoreList.ini";
			if(!xini_exist(File))
			{
				xini_create(File);
			}

			new Kills[10][256], KillsName[10][256], KillsValue[10], tmpp[256], idxx, vstring[1];
			for(new v=0; v<10; v++)
			{
				valstr(vstring, v);
				Kills[v] = xini_get(File,"Kills",vstring,true); //full string
				KillsName[v] = strtok(Kills[v], idxx); //name (1st part)
				tmpp = strtok(Kills[v], idxx); KillsValue[v] = strval(tmpp); //value (2nd part)
				idxx = 0;

				format(String, sizeof String, "%s %i", KillsName[v], KillsValue[v]);
				SendClientMessage(20, COLOR_BASIC, String);
			}
	  		return 1;
		}

		if(!strcmp(cmd,"/oread", true))
		{
			new File[64]= "ScoreList.ini";
			if(xini_exist(File))
			{
				new Kills[10][256], KillsName[10][256], KillsValue[10], tmpp[256], idxx, vstring[1];
			  	for(new v=0; v<10; v++)
			  	{
					valstr(vstring, v);
					Kills[v] = xini_get(File,"Kills",vstring,true); //full string
					KillsName[v] = strtok(Kills[v], idxx); //name (1st part)
					tmpp = strtok(Kills[v], idxx); KillsValue[v] = strval(tmpp); //value (2nd part)
					idxx = 0;

					format(String, sizeof String, "%s %i", KillsName[v], KillsValue[v]);
					SendClientMessage(20, COLOR_BASIC, String);
				}
				format(String, sizeof String, "ScoreList Kills:~n~~n~1: %24s %i~n~2: %24s %i~n~3: %24s %i~n~4: %24s %i~n~5: %24s %i~n~6: %24s %i~n~7: %24s %i~n~8: %24s %i~n~9: %24s %i~n~10: %24s %i~n~",
				KillsName[0], KillsValue[0], KillsName[1], KillsValue[1], KillsName[2], KillsValue[2], KillsName[3], KillsValue[3], KillsName[4], KillsValue[4], KillsName[5],
				KillsValue[5], KillsName[6], KillsValue[6], KillsName[7], KillsValue[7], KillsName[8], KillsValue[8], KillsName[9], KillsValue[9]);
				SendInfoText(playerid, 0, 200, String);
				PlayerPlaySound(playerid, CheckSound, 0.0, 0.0, 0.0);
			}
			else
			{
				PlayerPlaySound(playerid, ErrorSound, 0.0, 0.0, 0.0);
				SendInfoText(playerid, 1200, 103, "~r~Error_o.O");
			}
			return 1;
		}
if I /* */ one command, the warnings don't show
ғαιιοцт is offline  
Old 14/10/2009, 03:31 PM   #2
yom
Gangsta
 
Join Date: Jul 2006
Posts: 988
Reputation: 6
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

I guess your script use too much memory. Learn to script efficiently!
yom is offline  
Old 14/10/2009, 03:35 PM   #3
ғαιιοцт
High-roller
 
ғαιιοцт's Avatar
 
Join Date: Feb 2008
Posts: 1,428
Reputation: 188
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

I do script efficiently :l
it's just a large script


any other way?
I'm already using #pragma dynamic 10000
ғαιιοцт is offline  
Old 14/10/2009, 03:43 PM   #4
dice7
High-roller
 
Join Date: Apr 2009
Location: Slovenia
Posts: 2,200
Reputation: 22
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

Just hit control + f and search KillsName and Kills. And if you have to use #pragma dynamic, then you don't script efficiently. Look at YSI for example
dice7 is offline  
Old 14/10/2009, 03:46 PM   #5
ғαιιοцт
High-roller
 
ғαιιοцт's Avatar
 
Join Date: Feb 2008
Posts: 1,428
Reputation: 188
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

Quote:
Originally Posted by dice7
Just hit control + f and search KillsName and Kills.
I already said that I don't have the variables on the same level..
there's one other in the other command
and one other in OnPlayerDeath
that can't cause problems

Quote:
Originally Posted by dice7
And if you have to use #pragma dynamic, then you don't script efficiently. Look at YSI for example
I have optimised my script so that I don't use to large arrays
and I can't use any less memory.. I've just got a lot of arrays
ғαιιοцт is offline  
Old 14/10/2009, 03:56 PM   #6
yom
Gangsta
 
Join Date: Jul 2006
Posts: 988
Reputation: 6
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

Pr0s don't use #pragma dynamic. I never needed to use it, because i don't create variables such as Kills[10][256] INSIDE a function. In a function you should not create such big variables, if you need them to be that big, create them outside the function.

Quote:
Originally Posted by ғαιιοцт
I have optimised my script so that I don't use to large arrays
and I can't use any less memory.. I've just got a lot of arrays
10x256x2 cells is extremely large for Pawn, and that is your problem actually: your function require too much memory and will not work, and no your script isn't optimised at all...one exemple is that you still use strtok.
yom is offline  
Old 14/10/2009, 04:11 PM   #7
ғαιιοцт
High-roller
 
ғαιιοцт's Avatar
 
Join Date: Feb 2008
Posts: 1,428
Reputation: 188
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

so I'm clearly thinking wrong about how pawno works..

I thought that when I create a variable inside a function, it gets erased from the memory as soon as the function has ended?
so creating it at the top of my script, where it never gets deleted out of the memory, is better?
ғαιιοцт is offline  
Old 14/10/2009, 04:29 PM   #8
Extremo
Gangsta
 
Extremo's Avatar
 
Join Date: Jul 2008
Posts: 717
Reputation: 90
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

Well, pawno is statically allocated memory so even your small bit you parse into a function is still saved. Even though it gets re-set, yet it is still saved. Its only the remaining cells which are saved, not the full declared variable, but overall you will save much more space with global ones. Also global ones can handle more cells and are more efficient on the further go.

Here a example:
pawn Code:
Function1()
{
  new str[128];
  format(str, sizeof(str), "I am declaring a string, because I don't really give a damn and i am trying to explain somefing");
  print(str);
}
Function2()
{
  new str[128];
  format(str, sizeof(str), "I am declaring a string, because I don't really give a damn and i am trying to explain somefing");
  print(str);
}

Would be bad, but this one would be better:
pawn Code:
new str[128];
Function1()
{
  format(str, sizeof(str), "I am declaring a string, because I don't really give a damn and I am trying to explain somefing!");
  print(str);
}
Function2()
{
  format(str, sizeof(str), "I am declaring a string, because I don't really give a damn and I am trying to explain somefing!");
  print(str);
}

Well, when declaring a variable inside a bit of code in pawn it does use the dynamic memory blocks you have, but most likely these aren't many. Using global variables will make them also be declared in pawn itself and the address will remain static. So, after re-creating a intern variable around a million times, you will probably have more remaining saved cells, then when using a global variable you keep overwriting.
__________________
Extremo is offline  
Old 14/10/2009, 04:34 PM   #9
ғαιιοцт
High-roller
 
ғαιιοцт's Avatar
 
Join Date: Feb 2008
Posts: 1,428
Reputation: 188
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

and is it better to create the string "str" of your example at the beginning of the callback, or is it better to create it a the top of my script?
ғαιιοцт is offline  
Old 14/10/2009, 04:37 PM   #10
[HKS]dlegend
Huge Clucker
 
Join Date: Aug 2009
Posts: 210
Reputation: 0
Default Re: local variable "KillsName" shadows a variable at a preceding level (weird)

is it defied at the top of the script if so only define were it is need as a new maybe

im noob you see
[HKS]dlegend is offline  
 

Thread Tools
Display Modes

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Checkpoint & error 033: array must be indexed (variable "tmp") KyleOwnzYou Help Archive 2 08/05/2010 04:10 AM
(19879) : warning 219: local variable "mod" shadows a variable at a preceding le ReactionGameServers Help Archive 4 02/03/2010 08:23 PM
[Solved] Shadows variable at preceding level? bajskorv123 Help Archive 2 06/01/2010 10:14 AM
warning 219: local variable "timecounter" shadows a variable at a preceding leve PKRanger Help Archive 3 08/08/2009 04:04 PM
local variable "tmp2" shadows a variable at a preceding level Battlaman Help Archive 2 04/08/2009 06:10 PM


All times are GMT. The time now is 05:23 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.