Have you tried doing a pre-decrement of the temp.dam variable? I don't really think that it would matter, but it's worth a shot I guess. (pre-decrement is: --temp.dmg
Also, try echoing temp.dmg and temp.dmcheck, and see if they really are not the same.