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
|
|
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
|
|
|
|
|
|
"How does it work?" Part 8: Skill Checks
By: Headrock on Wed, 08 October 2008 15:40
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Headrock on Wed, 08 October 2008 15:42
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Panpiper on Wed, 08 October 2008 16:40
|
|
|
Re: "How does it work?" Part 8: Skill Checks
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Headrock on Wed, 08 October 2008 16:56
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: cdunigan on Wed, 08 October 2008 17:31
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Headrock on Wed, 08 October 2008 19:13
|
|
|
Re: "How does it work?" Part 8: Skill Checks
|
|
|
Re: "How does it work?" Part 8: Skill Checks
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Headrock on Wed, 24 December 2008 07:32
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Kaerar on Wed, 24 December 2008 08:09
|
|
|
Re: "How does it work?" Part 8: Skill Checks
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Kaerar on Thu, 25 December 2008 12:33
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Headrock on Thu, 25 December 2008 15:05
|
|
|
Re: "How does it work?" Part 8: Skill Checks
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Headrock on Thu, 25 December 2008 16:59
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: BirdFlu on Thu, 25 December 2008 20:26
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: Headrock on Fri, 26 December 2008 01:53
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: BirdFlu on Fri, 26 December 2008 02:54
|
|
|
Re: "How does it work?" Part 8: Skill Checks
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: BirdFlu on Fri, 26 December 2008 12:12
|
|
|
Re: "How does it work?" Part 8: Skill Checks
By: BirdFlu on Fri, 26 December 2008 12:21
|
Goto Forum:
Current Time: Mon Dec 02 10:51:37 GMT+2 2024
Total time taken to generate the page: 0.01135 seconds
|