Welcome Guest, Not a member yet? Register   Sign In
Message: Undefined property: stdClass::$HP
#1

[eluser]Unknown[/eluser]
Hey

I've got this error message and I can't seem to find the reason for it.
Quote:A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$HP
Filename: helpers/battle_helper.php
Line Number: 13

In my battle_helper.php I have this 2 functions :
Code:
function calculateStats($nature, $EV, $IV, $level){
    
    $base = calculateBaseStats();
    
    $stats = new stdClass();
    $stats->HP = (($IV->HP + 2 * $base->HP + ($EV->HP / 4)) * $level / 100) + 10 + $level;
    $stats->ATTACK = ((($IV->ATTACK + 2 * $base->ATTACK + ($EV->ATTACK / 4)) * $level / 100) + 5) * $nature->attack;
    $stats->DEFENCE = ((($IV->DEFENCE + 2 * $base->DEFENCE + ($EV->DEFENCE / 4)) * $level / 100) + 5) * $nature->defence;
    $stats->SPCATTACK = ((($IV->SPCATTACK + 2 * $base->SPCATTACK + ($EV->SPCATTACK / 4)) * $level / 100) + 5) * $nature->spcattack;
    $stats->SPCDEFENCE = ((($IV->SPCDEFENCE + 2 * $base->SPCDEFENCE + ($EV->SPCDEFENCE / 4)) * $level / 100) + 5) * $nature->spcdefence;
    $stats->SPEED = ((($IV->SPEED + 2 * $base->SPEED + ($EV->SPEED / 4)) * $level / 100) + 5) * $nature->speed;
    
    return $stats;
}]

Code:
function calculateBaseStats()
{
    $base = new stdClass();
    $base->HP = 0;
    $base->ATTACK = 0;
    $base->DEFENCE = 0;
    $base->SPCATTACK = 0;
    $base->SPCDEFENCE = 0;
    $base->SPEED = 0;
    
    return $base;
}

When I echo the $base->HP inside the calculateStats function. I get the value 0 on my webpage without the error. But the error still remains on line 13.

Is there a solution for my problem?
Thanks

Mankeeey
#2

[eluser]Iván Argulo[/eluser]
Well, I copy-pasted your code in a new PHP file and it worked perfectly (the only exception is the bracket at the end }]).
I tested it changing the values of HP and echoing them, and the result was the expected.




Theme © iAndrew 2016 - Forum software by © MyBB