I have a PHP script set up to regenerate a game character's statistics(health, energy, etc...). The approach I'm using is to store the result of a call to time() along with the character's data, and then when I pull the data out of the database I subtract the time of the last update from the current time, e.g:
Last update: 1264322000
Current time: 1264322357
Time elapsed: 357 seconds
That part works, the problem is the second part of the script:
$regen_remainder = $this->regen_secs - ($this->regen * 60);
echo "Regen remainder: " . $regen_remainder . "<br />"; // check value
echo "Current time: " . $this->current_time . "<br />"; // check value
$this->lastupdate = $this->current_time - $regen_remainder;
echo $this->lastupdate; // check value
The results of the three "echo" statements are as follows:
Regen remainder: 57
Current time: 1264322357
1.2643223E+09
It always produces a completely different number(usually +~40 instead of -whatever), messing up the next few calculations. I can't seem to figure out why it's doing this. Any ideas?