local variable "len" shadows a variable at a preceding level
#1

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(playeridstatssizeof(stats));
  new 
len strfind(stats"PacketLoss: ");
  new 
Float:packetloss 0.0;
  if(
len != -1)
  {
      
strmid(stringstatsstatslenstrlen(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;

Reply
#2

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.
Reply
#3

Oh, ye i saw something like that when i searched, i didn't know what did i define twice.

Alright, thank you very much.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)