Save Color() to .json file

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

The problem is this, I wrote the color from the picker to a file, and I need to load it. However! Godot does not understand the resulting values

Sample code (I wrote it separately, because half of the project needs to be disassembled to show these particular lines):

    extends Node2D


var savecolor = Color(1, 1, 1, 1)
var truecolor = Color(savecolor)


func _process(delta):

	savecolor = $test/ColorPicker.color
func _on_Start_Game_pressed():
	Saver1.save({
		"main" : {
			"color" : savecolor
		}
	})


func loading():
	savecolor = Saver3.saveData.main.color

I tried many solutions. I would be grateful for your help

:bust_in_silhouette: Reply From: AlexTheRegent

You need to convert Color to one of the serializable types. One of the ways of doing so is to use to_html method:
"color": savecolor.to_html()
This method will give string and strings can be saved in JSON.
To load this color you can use Color Color(from: String) constructor:
savecolor = Color(Saver3.saveData.main.color)

And I could not think about html. Thank you so much!

JerryHayat | 2021-01-04 17:46