SA-MP Forums Archive
local variable "KillsName" shadows a variable at a preceding level (weird) - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: local variable "KillsName" shadows a variable at a preceding level (weird) (/showthread.php?tid=102237)



local variable "KillsName" shadows a variable at a preceding level (weird) - ғαιιοцт - 14.10.2009

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


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - yom - 14.10.2009

I guess your script use too much memory. Learn to script efficiently!


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - ғαιιοцт - 14.10.2009

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


any other way?
I'm already using #pragma dynamic 10000


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - dice7 - 14.10.2009

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


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - ғαιιοцт - 14.10.2009

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


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - yom - 14.10.2009

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.


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - ғαιιοцт - 14.10.2009

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?


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - Extremo - 14.10.2009

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.


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - ғαιιοцт - 14.10.2009

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?


Re: local variable "KillsName" shadows a variable at a preceding level (weird) - [HKS]dlegend - 14.10.2009

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