0 votes

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

in Engine by (65 points)

1 Answer

0 votes
Best answer

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)

by (1,116 points)
selected by

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.