Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: General Battuta on November 28, 2020, 10:29:00 pm

Title: Did you know that FRED can't count to 100?
Post by: General Battuta on November 28, 2020, 10:29:00 pm
(This only applies to certain percentage-based values)

Set a ship's weapon ETS to 0 (lock it so the AI can't put power back in weapons). Set its weapon energy to 0.

Add 1 to the ship's weapon energy percent every second.

You'll never hit 100!
Title: Re: Did you know that FRED can't count to 100?
Post by: Mobius on November 29, 2020, 05:12:49 am
Did you know that the 100th argument in a SEXP will be marked as "0"?  :nervous:
Title: Re: Did you know that FRED can't count to 100?
Post by: TopAce on November 29, 2020, 05:54:42 am
Is this similar to the Y2K problem in its foundation?
Title: Re: Did you know that FRED can't count to 100?
Post by: AdmiralRalwood on November 29, 2020, 03:00:29 pm
Is this similar to the Y2K problem in its foundation?
Not quite. It's a floating-point rounding error; certain numbers that are nice, round numbers in decimal (like 0.52, since Battuta ran into this problem at 52%) aren't nice, round numbers in binary. Since the SEXP code turns that floating-point number into an integer through truncation, 52% winds up rounding into 51, so when 1 is added it just brings it back up to 52... where it started. Technically, we could fix this (by using a higher precision floating-point format and/or rounding instead of truncating), but it's honestly a very low-priority problem (since you can work around it by just using an increment larger than 1).