Killian Jayaram 0 Posted May 20 I am trying to figure out a hit system based on enemy strength with user programmable strength and my code looks a little something like this... integer my_health = 100; // TAKES 10 HITS TO KILL ME IF NUMBER IS 100 integer health = 100; take_hit(integer strength){ integer hit_math = (strength /my_health) * 100; health = health - hit_math; } default{ touch_end(integer num){ take_hit(10); } } but for some reason "hit_math" keeps returning 0. Now maybe I have not had enough coffee yet but the math should work ( (10/100) * 100 = 10 ), what am I doing wrong? Quote Share this post Link to post Share on other sites
Profaitchikenz Haiku 332 Posted May 20 Multiply first and then divide, otherwise the division might result in too small a result. As you are using integers, if the result is less than 1 no amount of subsequent multiplication is ever going to raise it above zero. Quote Share this post Link to post Share on other sites
Wandering Soulstar 100 Posted May 20 Or change them to floats for the operation and then back to integer Quote Share this post Link to post Share on other sites
Killian Jayaram 0 Posted May 20 Yeah thanks setting them to floats worked Quote Share this post Link to post Share on other sites