Home » MODDING HQ 1.13 » v1.13 Modding, Customising, Editing » v1.13 Time Capsule (How-to Library) » "How does it work?" Part 8: Skill Checks
Re: "How does it work?" Part 8: Skill Checks[message #204884] Thu, 25 December 2008 15:05 Go to previous messageGo to previous message
Headrock

 
Messages:1760
Registered:March 2006
Location: Jerusalem
Quote:
Automatic conversions to integer? I don't remember that from my C++ programming classes in high school. Must have missed that while I was busy writing papers for my PSEOP college English class while the C++ teacher wasn't looking. Can you tell me when integral conversions would occur? Would it just round decimals to the nearest integer? I can come up with an accurate idea of whether that system is working as intended or giving an absurdly big bonus to unskilled players.


It doesn't only round decimals to the nearest integer, it also converts integers into one another, if I remember correctly. I think the conversion always tries to end up with an integer of the type of the variable into which the result of the formula is going, so I would assume that a target float would not cause automatic conversions to integer. But I'm not a coder per-se, so this is just a wild guess.

In any case, bad construction of a formula usually ends up with lopsided results, in cases where you've got division somewhere that's supposed to end up with significant fractions. To avoid this you either find some way to put the division last in the formula, or set up "store as" commands like "(float)" or "(double)" to make sure the value doesn't get truncated.

Example:

Result = (Base_Value / 100) * Percentage_Value // INCORRECT!
Result = (Base_Value * Percentage_Value) / 100 // CORRECT!

In the above example, the mathematics are exactly the same, but the results aren't.

Assuming that Result is an INT variable, and Base_Value<=100, the first syntax will usually return 0. That's because the first part ("Base_Value/100") would be a fractional number between 0 and 1, and thus would be automatically converted to 0.
By putting the division last, as in the second syntax, you make sure that fractions are irrelevant. Of course, that only applies when working with Integers, I don't think the auto conversion would occur when the result is expected to be a float or double.

Report message to a moderator

Sergeant Major

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: "How does it work?" Part 1: Bullet Impact
Next Topic: "How does it work?" Part 5: Melee Combat Chance-to-Hit
Goto Forum:
  


Current Time: Mon Dec 02 10:51:37 GMT+2 2024

Total time taken to generate the page: 0.01135 seconds