Okay, I got this function to calculate the experience.
I can input the attacker level, the defender level and wheter it's a match against a trainer or against a player.
here's the function:
function experience($alvl,$dlvl,$t)
{
if($t == 1)
{
$exp = rand(($dlvl * 19),($dlvl * 19) + rand(0,2*$dlvl));
$silver = round(rand($dlvl*1.5, 2 * $dlvl));
}
else
{
$exp = round($dlvl * 40 * ($dlvl / $alvl));
if($dlvl == $alvl) $exp = round($exp * 1.5);
elseif($dlvl > $alvl) $exp = $exp * 2;
$silver = round((2/3) * $exp);
}
$ret['silver'] = $silver;
$ret['exp'] = $exp;
return $ret;
}
But this doesn't work and I dont know why! If i take out the lines $ret[silver] = $silver; and $ret[exp] = $exp; in the else {} statement, it works. If I leave them in, it wont work. Meaning it won't work as in the whole page is blank (this is a function in a file that gets included on every page)
Can anyone tell me what's wrong here? (I've had this problem mutliple times now with the same method of returning an array by a function. Sometimes it worked when I put one line before the other, but not the other way around... I'm getting confused here)
- Sinzygy