+1 vote

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

asked Jun 26, 2019 in Projects by Firty (23 points)

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).

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.

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 = []
file.open(url, File.WRITE)

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 = parsejson(file.getas_text())
$Sprite.modulate = a[0]

Hope this helps.

Thank you very much, I solved the problem

Please log in or register to answer this question.

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.