Jump to content
Killian Jayaram

LSL Operators Division Problem?

Recommended Posts

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...