Jump to content

What's wrong with big FLOAT variables?


JustChill

Recommended Posts

Hey there,

I just wanted to include the default presets of New Vegas into my Dynamic Pipboy Light mod:

            Let DPLightDefaultCol := GetNumericINISetting "uPipboyColor:Interface"    ;=> Don't ask me why, but the FLOAT variable was faulty. Even if it represented'
            Let DPLightDefCol := sv_construct "%.0f" DPLightDefaultCol        ;=> the very exact value shown below, the condition wasn't met. With a STRING it works. -.-'
            if eval DPLightDefCol == "785383423"    ;=> Blue default color
                Let DPLightRed := 46                    ;=> Alright, instead of taking over the color, I rather wanted to check which default color
                Let DPLightGreen := 207                ;=> is set and take over this one. I don't know how this color gets applied, but the Pipboy RGB colors itself'
                Let DPLightBlue := 255                ;=> (from the light source), never changes. It's always the same value.'
                Let DPLightRedI := 46    
                Let DPLightGreenI := 207
                Let DPLightBlueI := 255
            elseif eval DPLightDefCol == "452952319"        ;=> Green default color
                Let DPLightRed := 26
                Let DPLightGreen := 255
                Let DPLightBlue := 128
                Let DPLightRedI := 26
                Let DPLightGreenI := 255
                Let DPLightBlueI := 128
            elseif eval DPLightDefCol == "3321888767"        ;=> White default color
                Let DPLightRed := 197
                Let DPLightGreen := 255
                Let DPLightBlue := 255
                Let DPLightRedI := 197
                Let DPLightGreenI := 255
                Let DPLightBlueI := 255
            elseif eval DPLightDefCol == "4290134783"        ;=> Amber default color
                Let DPLightRed := 255
                Let DPLightGreen := 182
                Let DPLightBlue := 66
                Let DPLightRedI := 255
                Let DPLightGreenI := 182
                Let DPLightBlueI := 66
            else
                Let DPLightRed := GetLightTraitNumeric PipboyLight640 1        ;=> In the case where none of the default values match (as the player changed the INI)
                Let DPLightGreen := GetLightTraitNumeric PipboyLight640 2    ;=> we at least apply the current light values (which are mostly always the same, except
                Let DPLightBlue := GetLightTraitNumeric PipboyLight640 3        ;=> a mod alters the pipboy light values itself.)
                Let DPLightRedI := GetLightTraitNumeric PipboyLight640 1
                Let DPLightGreenI := GetLightTraitNumeric PipboyLight640 2
                Let DPLightBlueI := GetLightTraitNumeric PipboyLight640 3
            endif

Getting "uPipboyColor" was easy, but using the results in a float variable didn't trigger the conditions in the IF block.

Even if it was exactly the same value I state here (as seen in the INI file for everyone too).

Only if I convert the float to a string variable by using sv_construct for making it completely identical to the float it works.

Surely I need to use "eval" and put the numbers into quotes for the query, but at least the conditions are met now.

 

Any idea why that's so?

I now have a useless string variable just for this. :sad:

 

 

In addition: I will misuse a present string variable just for this, so I won't need one useless extra variable. ^^

But I am still wondering, why this is an issue.

 

elseif DPLightDefaultCol == 4290134783

In the case of the float, I used

 

printc "%.0f" DPLightDefaultCol

and got "4290134783" printed out into Console. I really don't get why the condition isn't met then. oO

 

So even if I somewhat "fixed" it by using a string for the query, I still ask out of curiosity.

Link to comment
Share on other sites

It's because the value is stored as an "implied decimal value" and an "==" comparison will never match exactly.

 

From the GECKWiki page description for "Float":

Imprecision Warning

Beware that floats are imprecise in computer science due to the impossibility of expressing most fractions in binary.

For example, in standard decimal it is impossible to express the fraction '1/3'- it must be approximated (0.3333...). The same situation applies much more often in binary.

In general, this should not pose a problem in GECK context, but one should be weary testing floats for exact equality (==). To be safe, one should Floor before checking, or instead use '<=' or '>='.

 

When you convert the number, the decimal point is removed/truncated to only the significand.

 

-Dubious-

Link to comment
Share on other sites

I've also checked with

printc "%.5f" DPLightDefaultCol

and got "4290134783.00000" into console. oO

 

So you say that the empty decimal values were to fault that query? :O

 

That's weird, I previously used float varibles with "==1", but that was before I set them to :=1 with Let, to be honest.

I mainly wanted to use something else than float for this anyways, but these numbers are even too high for the Long. :sad:

 

Anyways, thanks for that. I'll try out using floor on the gathering. :smile:

 

 

In addition:

It doesn't work.

I've changed the query again with using a floored float variable:

            Let DPLightDefaultCol := GetNumericINISetting "uPipboyColor:Interface"
            Let DPLightDefaultCol := floor DPLightDefaultCol
            if DPLightDefaultCol == 785383423    ;=> Blue default color
                Let DPLightRed := 46                    ;=> Alright, instead of taking over the color, I rather wanted to check which default color
                Let DPLightGreen := 207                ;=> is set and take over this one. I don't know how this color gets applied, but the Pipboy RGB colors itself
                Let DPLightBlue := 255                ;=> (from the light source), never changes. It's always the same value.
                Let DPLightRedI := 46    
                Let DPLightGreenI := 207
                Let DPLightBlueI := 255
            elseif DPLightDefaultCol == 452952319        ;=> Green default color
                Let DPLightRed := 26
                Let DPLightGreen := 255
                Let DPLightBlue := 128
                Let DPLightRedI := 26
                Let DPLightGreenI := 255
                Let DPLightBlueI := 128
            elseif DPLightDefaultCol == 3321888767    ;=> White default color
                Let DPLightRed := 197
                Let DPLightGreen := 255
                Let DPLightBlue := 255
                Let DPLightRedI := 197
                Let DPLightGreenI := 255
                Let DPLightBlueI := 255
            elseif DPLightDefaultCol == 4290134783        ;=> Amber default color
                Let DPLightRed := 255
                Let DPLightGreen := 182
                Let DPLightBlue := 66
                Let DPLightRedI := 255
                Let DPLightGreenI := 182
                Let DPLightBlueI := 66
printc "Now with a floored DPLightDefaultCol."
            else
                Let DPLightRed := GetLightTraitNumeric PipboyLight640 1        ;=> In the case where none of the default values match (as the player changed the INI)
                Let DPLightGreen := GetLightTraitNumeric PipboyLight640 2    ;=> we at least apply the current light values (which are mostly always the same, except
                Let DPLightBlue := GetLightTraitNumeric PipboyLight640 3        ;=> a mod alters the pipboy light values itself.)
                Let DPLightRedI := GetLightTraitNumeric PipboyLight640 1
                Let DPLightGreenI := GetLightTraitNumeric PipboyLight640 2
                Let DPLightBlueI := GetLightTraitNumeric PipboyLight640 3
printc "Ehm... What?"
            endif

This is the result ingame:

 

Picture of ingame Pip Boy light default settings (LINK).

 

Picture of the console message, when starting a new game to initialize mod (LINK).

 

 

Seems I have to stick with my solution of converting it to a string. :/

Link to comment
Share on other sites

I know about integers, but the ints in Fallout New Vegas range from −2,147,483,647 to +2,147,483,647.

That's too low for the color values located in the Game INI. They cannot hold that amount, so I have to use floats.

785383423

452952319 Lowest color value

4290134783 Highest color value

VS

2147483647 Max int size.

 

It works on the lowest color value with ints, but the highest ones are simply too much for using an int variable.

It's the only way to save the correct values using floats and converting them to a string.

That fixes my issue anyways, so I will use that solution. :smile:

Link to comment
Share on other sites

I know about integers, but the ints in Fallout New Vegas range from −2,147,483,647 to +2,147,483,647.

That's too low for the color values located in the Game INI. They cannot hold that amount, so I have to use floats.

785383423 Lowest color value

4290134783 Highest color value

VS

2147483647 Max int size.

 

It works on the lowest color value with ints, but the highest ones are simply too much for using an int variable.

It's the only way to save the correct values using floats and converting them to a string.

That fixes my issue anyways, so I will use that solution. :smile:

 

So the GECK only does signed integers. What would be best, now that I think about it, is for NVSE to add unsigned integers. Wonder if NVSE is still developed.

Link to comment
Share on other sites

I don't know. :sad:

Even though I am not sure if unsigned ints might be necessary.

Actually I am a bit more annoyed about the decimal color values used by Bethesda (Obsidian took that over unfortunately) in the FalloutPrefs.ini.

"uPipboyColor" actually works with regular decimal values, that only get solved when converting into hex.

Blue:    785383423    = 2ECFFF FF = 46R  207G 255B
Green:    452952319    = 1AFF80 FF = 26R  255G 128B
White:    3321888767    = C5FFFF FF = 197R 255G 255B
Amber:    4290134783    = FFB642 FF = 255R 182G 66B

Regular decimal color codes are never bigger than 16777215. I am not sure why they added so much to it, that every color code in hex value has an extra "FF" at the end.

By doing so, the decimal values are bigger than the int values used by the game.

If they used the regular decimal values it would have been possible without using that string conversion workaround. :/

Link to comment
Share on other sites

I never tried to play around with these values in the FalloutPrefs.ini. ^^

But maybe without these extra FF, the light value doesn't work at all?

I've heard people are using these to change their Pip-Boy light color, even though I think that's pretty inconvenient.

I am not bothered enough to try it out, to be honest. XD

 

I mainly use these values to determine which current setting the player has chosen under "Settings" > "Display", where you can change the Pip-Boy default color.

Just happy that I was able to find the solution of converting these to strings for comparison. The changes get written into the INI file on the fly.

I can say that for sure, because I use the check on these values with "GetNumericINISetting" in MenuMode 1013. Everytime these get changed, my Pip-Boy light mod adapts to the changed setting. :smile:

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...