Killi Cloud Posted May 20, 2019 Share Posted May 20, 2019 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? Link to comment Share on other sites More sharing options...
Profaitchikenz Haiku Posted May 20, 2019 Share Posted May 20, 2019 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. Link to comment Share on other sites More sharing options...
Wandering Soulstar Posted May 20, 2019 Share Posted May 20, 2019 Or change them to floats for the operation and then back to integer Link to comment Share on other sites More sharing options...
Killi Cloud Posted May 20, 2019 Author Share Posted May 20, 2019 Yeah thanks setting them to floats worked Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now