Invalid Color Code

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

01
02
03
04
My project has a save and load mode, when I save this everything works very well, but when I try to give load the engine does not accept the colors that have been saved. When I create the character, I define the color by mudalate, in the case of load I only try to make the variable receive the saved numbers. If I print modulate color I get the same value that is saved in the save game file. Load game is working fine, loads everything I defined, but the character’s colors turn black.
I’m probably messing around in the form of uploading, but I’ll turn the internet behind information and find nothing …

Godot 3.1.1

by Google translator

I solved my problem by converting the colors before saving the game, using to_html () … Strange it does not load the colors with the numbers (0 to 1).

Firty | 2019-06-26 20:30

Hello! I have your same problem, but I don’t understand how did you solve your problem. Can you send your updated code? Thank you very much.

Andrea1141 | 2020-04-05 15:03

var url:String = “user://test.bin”
var skincolor:Color
onready var file:File = File.new()

func _ready():
skincolor= $Sprite.modulate

func save() → void:
var skinhtml = skincolor.to_html()
var a:Array =
a.append(skinhtml)
file.open(url, File.WRITE)
file.store_line(to_json(a))
file.close()

To save, just convert the var “Color” using to_html() (it will become a Hex code [green becomes ff00ff00]).
To load it looks like this:

func load():
file.open(url, File.READ)
var a = parse_json(file.get_as_text())
file.close()
$Sprite.modulate = a[0]

Hope this helps.

Firty | 2020-04-06 03:02

Thank you very much, I solved the problem

Andrea1141 | 2020-04-06 12:51