Re: how to create an if-then statement for if a value changes?
Hard to make more streamlined than that, really. The only possible thing would be that you aren't checking for positive health changes, but given what you're using it for, that shouldn't be an issue. I think that lifeCTimer is redundant, however, since it just equalizes health and actorHP every 200 milliseconds.
If i were to give an untested(!!!) take on it (and if you're even at all interested), here you go:
Code:
function Create(self)
self.oldHealth = self.Health;
self.healDelayTimer = Timer();
self.healDelay = 8000;
self.healTimer = Timer();
self.healInterval = 400;
end
function Update(self)
local healthDiff = self.Health - self.oldHealth;
if healthDiff < 0 then
self.healDelayTimer:Reset();
end
if self.healDelayTimer:IsPastSimMS(self.healDelay) and self.Health < 100 then
if self.healTimer:IsPastSimMS(self.healInterval) then
self.Health = self.Health + 1;
self.healTimer:Reset();
end
end
self.oldHealth = self.Health;
end
This is only a tiny bit shorter, and the only functional difference is that it has a variable for the health difference in the current frame, which could potentially be used for more shenanigans.
So yeah, to answer your original question: Pretty much how you did it. Store the previous value in a different variable, and compare it to the current value.