does not exists

Started by Cool, Nov 05, 2015, 04:06 PM

Previous topic - Next topic

Cool

error 0 does not exists on getstats all my stats function
error line if ( ( kills > 0 ) && ( deaths > 0 ) )function SaveStats( player )
{
   local id = player.ID;
   {
       QuerySQL( db, "UPDATE Account SET Kills='" + stats[ id ].Kills + "', Deaths='" + stats[ player.ID ].Deaths + "', Cash='" + stats[ id ].Cash + "', Bank='" + stats[ id ].Bank + "', Joins='" + stats[ id ].Joins +  "' WHERE Name='" + player.Name.tolower() + "'" );
   print( "Saved Stats of Player " + player.Name + "[" + player.ID + "]" );
   stats[ id ] = null;
   }
   }
function GetStats( p )
{
   local stats = null;
   {
   local id = p.ID;
   local kills = stats[ id ].Kills, deaths = stats[ id ].Deaths;
   if ( ( kills > 0 ) && ( deaths > 0 ) )
   {
       local ratio = format( "%.2f", kills.tofloat() / deaths.tofloat() );
   stats = "Kills: " + kills + ", Deaths: " + deaths + ", Ratio: " + ratio + ".";
   }
   else
   {
       stats = "Kills: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
   }
   }
   return stats;
   }
 
function ExecStats()
{
try{
for(local i = 0; i < GetMaxPlayers(); i++)
    {
        local player = FindPlayer( i ),q;
    if ( player )
    {
    local id = player.ID
   local  q = QuerySQL( db, "UPDATE Account SET Kills='" + stats[ player.ID ].Kills + "', Deaths='" + stats[ player.ID ].Deaths + "', Cash='" + stats[ player.ID ].Cash + "', Bank='" + stats[ player.ID ].Bank + "' WHERE Name='" + player.Name.tolower() + "'" );
 FreeSQLQuery( q );
print("Executed stats")
     }
}
}
catch(e) print("Executing stats error "+e);
}

rulk

In GetStats you've got a extra brace { under
local stats = null;
We are all god's children.

Cool

i removed but same error :P

KAKAN

#3
function GetStats( p )
{
    local stats = "";
    {
    local id = p.ID;
    local kills = stats[ id ].Kills, deaths = stats[ id ].Deaths, ratio = format( "%.2f", kills.tofloat() / deaths.tofloat() );
if( p )
{
    if ( kills > 0 ) stats = "Kills: " + kills + ", Deaths: " + deaths + ", Ratio: " + ratio + ".";
    else  stats = "Kills: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
    }
}
    return stats;
    }
Try this one tho and tell the results.
oh no

rulk

This is @KAKAN's version, he forgot to remove the extra brace, i spotted two :-)
function GetStats( p )
{
    local stats = "";
    local id = p.ID;
    local kills = stats[ id ].Kills, deaths = stats[ id ].Deaths, ratio = format( "%.2f", kills.tofloat() / deaths.tofloat() );
    if ( kills > 0 ) stats = "Kills: " + kills + ", Deaths: " + deaths + ", Ratio: " + ratio + ".";
    else  stats = "Kills: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
    return stats;
}
We are all god's children.

Cool

your and rulk function both have same error 0 does not exists

KAKAN

Oh, yea, maybe that's the problem.
@King aka Noob, Try rulk's one.
And if it doesn't works, post the command for which you're using GetStats
oh no

KAKAN

#7
Quote from: King on Nov 05, 2015, 04:35 PMyour and rulk function both have same error 0 does not exists
Okay, then lets goto debugging mode.
Try adding this before the kills > 0 thing.
print( kills )
EDIT:-
Wait, I found the bug.
Use this one and try:-
function GetStats( p )
{
    local stats = "";
    local id = p.ID;
    local kills = stats[ id ].Kills, deaths = stats[ id ].Deaths, ratio = format( "%.2f", kills.tofloat() / deaths.tofloat() );
    if( !stats[ id ].Logged ) stats = "Kills: 0, Deaths: 0, Ratio: 0.";
else{
    if ( kills > 0 ) stats = "Kills: " + kills + ", Deaths: " + deaths + ", Ratio: " + ratio + ".";
    else  stats = "Kills: " + stats[id].Kills + ", Deaths: " + stats[id].Deaths + ".";
}
    return stats;
}
oh no

Cool

else if ( cmd == "stats" )
  {
  try{
    if ( !text ) EMessage( ">> " + player.Name + "'s Stats: " + GetStats( player ) );
else if ( text )
{
    local plr = GetPlayer( text );
if ( !plr ) ePrivMessage( "Invalid Player Nick/ID!", player );
else PrivMessage( plr.Name + "'s Stats: " + GetStats( plr ), player );
}

}
catch(e) print( "Stats Cmd Error: " + e );
  }

rulk

#9
change
local stats = "";

To
local stats = 0;

because your declaring stats as a string when it should be a integer.

edit, stats should be a string (doh), the error 0 dose not exists sound like kills and deaths are not set as integers
We are all god's children.

Cool

is there any mistake possible in class
///  Player Class
class PlayerStats
{
LastUsedIP = "0.0.0.0";
Cash = 0;
Bank = 0;
Kills = 0;
Deaths = 0;
Level = 0;
Logged = false;

rulk

apart from missing a brace at the bottom, no.

///  Player Class
class PlayerStats
{
    LastUsedIP = "0.0.0.0";
    Cash = 0;
     Bank = 0;
     Kills = 0;
     Deaths = 0;
     Level = 0;
    Logged = false;
}
We are all god's children.

Cool

no i have more functions so i closed in last

DizzasTeR

The class vars seem to be of Fuzzie's account system, so tell me I never remember that Fuzzie used 'stats' for declaring array, he used 'pstats'

Change all your stats to pstats.

Cool