Is there a method of saving an unsigned int to a file using ConfigFile?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kuydrac

I noticed when I saved a large seed number generated by randi() to a config file using ConfigFile, the number saved was different. I tried a few numbers until I realized it was saving the unsigned integer as a signed integer.

config.set_value("Config","test_value32",2147483649)

If I check the file, it shows the number as negative since bit 32 is set.

test_value32=-2147483647

When I read the file back and print the contents I get the same negative value instead of the positive value I started with.

print(config.get_value("Config", "test_value32"))

Output is:

-2147483647

To get around this, I could switch to using File instead of ConfigFile and save the data in a json format. That seemed to work correctly when I did a quick test. Another option I thought of was that I could possibly create a function to convert the signed 32 bit integer into an unsigned integer when reading back.

what version of godot are you using?

volzhs | 2019-01-29 08:21

I’m using Godot 3.0.6

kuydrac | 2019-01-29 16:55

there’s no uint for gdscript.
but godot supports 64 bit integer.
I’m not sure 3.0.x too.
would you try it with 3.1.beta?

volzhs | 2019-01-29 17:44

Same behavior with 3.1 beta

kuydrac | 2019-01-29 22:52

var test = 2147483649
print(test)  # this prints correctly 2147483649

so I guess it’s a kind of bug.
you need to report it on github issues.
Issues · godotengine/godot · GitHub

volzhs | 2019-01-30 03:52