+ 1

# My current coding challenge.

I have a function I need to spit out a number between 16 and 10,000. Context: HP damage. Given that it accepts inputs x, y, z. x will never be below 1 or above 99. y will be between 15 and 255. z same rules as y. ie. (levelX + 2*atkY) - defZ = 16; // Here's the low end Getting from there to the high end is the problem. With this formula, 594 is the top. Which I could use, but I would have to scale my ideas down. (99 + 510) - 15 Any bright ideas?

12 Answers

+ 1

Oh I made a mistake, sorry ! You have to do : /(MaxOfCurrentRange - MinOfCurrentRange) instead of /MaxOfCurrentRange

+ 4

I'm a game programmer. I see that you have a function to calculate damage output, but I don't quite understand your issue. Are the numbers outside of the range that you were anticipating?

+ 3

Thanks for the response. Seems legit if I plug in proper top end values. Hmm.

+ 2

ok, not my piece of cake, good luck

+ 2

If I'm understanding.
Top end result, for example.
(594 - 16)/594 * (10000-16) + 16
= (578 / 594 * 9984) + 16
= 9731.07 repeating...
did I do something wrong? Seemed so legit at first
Plug in low end.
(0 * 9984) + 16 = 16, that works.

+ 1

i would just do hitValue%maxHit if it is 20x greater than your ideal range.

+ 1

@tom, your suggestion imply behaviors not wanted in a game. If the player has an attack and a level which makes the operation go to a multiple of maxHit+1, it will do 0 damage, but with just one level less, it will do maximum of damage
You should do :
(result - MinOfActualRange)/MaxOfActualRange*(MaxRangeWanted - MinRangeWanted) + MinRangeWanted
With this formula, the result will be a projection of the old range in the new (like converting the reduction of a price from % to actual money)

0

unclear definition of the problem, as far as I am concerned. is this related to some HP hardware? some detailed illustration would help

0

Working on a roleplaying game. HP as in Health Points. I can be more specific if u need.

0

@Tom, can u elaborate a bit?

0

hitValue = (levelX +2*atkY)-defZ;
hitvalue%(maxHit+1);//would always result in a value less than or equal to maxHit

- 1

Yeah, thats the problem @Keto, looking for help making my formula output the right range