local variable "len" 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 "len" shadows a variable at a preceding level (
/showthread.php?tid=561456)
local variable "len" shadows a variable at a preceding level -
Glossy42O - 03.02.2015
Hello,
I'm having a little weird problem, I don't really know what's wrong, I saw someone said change the stock name.
I did it, nothing happened.
Here is the code:
PHP код:
stock Float:GetPlayerPacketLossFromServer(playerid)
{
new stats[401], stringstats[70];
GetPlayerNetworkStats(playerid, stats, sizeof(stats));
new len = strfind(stats, "PacketLoss: ");
new Float:packetloss = 0.0;
if(len != -1)
{
strmid(stringstats, stats, len, strlen(stats));
new len = strfind(stats, "Packetloss: "); <<<<<<<Line
if(len != -1)
{
strdel(stats, 0, strlen(stats));
strmid(stringstats, stats, len, strlen(stats));
packetloss = floatstr(stats);
}
}
return packetloss;
}
Re: local variable "len" shadows a variable at a preceding level -
CalvinC - 03.02.2015
It has nothing to do with the stock name.
pawn Код:
new len = strfind(stats, "PacketLoss: "); // Defined "len"
new Float:packetloss = 0.0;
if(len != -1)
{
strmid(stringstats, stats, len, strlen(stats));
new len = strfind(stats, "Packetloss: "); // You define it again, confusing the script
You define the same thing twice, remove one of them.
Re: local variable "len" shadows a variable at a preceding level -
Glossy42O - 03.02.2015
Oh, ye i saw something like that when i searched, i didn't know what did i define twice.
Alright, thank you very much.