file.store_var() in 3.5 to godot 4
For reference, here's the github issue:
https://github.com/godotengine/godot/issues/69114
DaveTheCoder I was the one who made it....
- Edited
I assumed that you posted the issue. I placed the link here so that people who see this topic know that the issue has been reported, and can view the issue for more information.
- Edited
- Best Answerset by jonSS
I think I found the cause of the problem:
https://github.com/godotengine/godot/issues/69114#issuecomment-1326955060
I don't know if that's a bug that will be fixed, or an intrinsic set_var/get_var incompatibility between Godot 3 and 4.
DaveTheCoder It has to be the cause, i think the store_var() files are identical. You found it, its the numeric type codes.
DaveTheCoder do you know if there's a way to change the file to TYPE_DICTIONARY = 27 ?
from the little i was able to found this ( enum Variant ) can only be changed outside of godot, and read when godot is starting.
- Edited
I was going to experiment with that using a binary file editor. But it's not a simple one-level Dictionary. It's a complex Dictionary that contains other Dictionaries, so fixing it manually would be difficult.
You could re-write the file using Godot 4.
A workaround for this issue is to use a different way of saving the data, such as ConfigFile.
- Edited
DaveTheCoder It would be easier if i could reSave it in 3.5. Is is possible to save it in ConfigFile using the node FileDialog ?
i have this save function
func _saveAnim():
if ( saveFileName == "" ):
saveFileName = "noName";
var file = File.new()
file.open(saveFileName, File.WRITE)
file.store_var(root1);
file.close()
saveLock = false;
- Edited
jonSS Is is possible to save it in ConfigFile using the node FileDialog ?
FileDialog simply provides the file name, so you can use ConfigFile in place of File.
The documentation has an example:
https://docs.godotengine.org/en/stable/classes/class_configfile.html#configfile
Since you're saving one variable, you only need to call set_value() once. And to load the file, call get_value() once.
The file will be plain text (unless you use save_encrypted), so you can view it easily outside of Godot.
- Edited
DaveTheCoder Yeah but i dont think i can do it... I tried to save to jSon the 1st i rebember something wasnt working... I think it was converting the root1 to String.
The config usess .set_value for each field, i think i would need to change the fields one by one ?
If it was something like changing the --- file.store_var(root1); --- to --- config.set_value(root1); --- it would be easy, i just dont think it will work... i would have to run a loop, i might need to change the entire program ?
An example of ( root1 ) can be easly created for testing...
var saveFileName = "";
var root1 = {
'Fnum': [0]
}
func _createAnim():
root1.Fnum.resize(1);
for n in range(1):
root1.Fnum[n] = {
"pt1": { "fm": dt1_Fm, "pos":dt1_Po, "pz": dt1_Z, "pa": dt1_A, "up1": dt1_Up1, "up2": dt1_Up2, "up3": dt1_Up3, "md1": dt1_Md1, "md2": dt1_Md2, "md3": dt1_Md3, "dn1": dt1_Dn1, "dn2": dt1_Dn2, "dn3": dt1_Dn3 }
}
convert all to string or save it has config... then in gd4 convert it back to a var ?
jonSS The config usess .set_value for each field, i think i would need to change the fields one by one ?
Do you mean that ConfigFile also depends on the Variant numeric type codes? I haven't tested that, but it makes the incompatibility more serious. I'll try to verify that, and add a comment to the github issue if it's true.
- Edited
DaveTheCoder no, config is fine... this seems work
in 3.5 save var(dictionary) root1 to config
var convertName = "res://convertAnims/1Jump.cfg";
if ( b_buttonCFG.is_pressed() ):
var config1 = ConfigFile.new();#------------------------ok
config1.set_value("Player1", "best_score", root1); #----ok
config1.save(convertName);
in 4.0
var convertPathLoad = "res://animConvert/1Jump.cfg";
var convertPathSave = "res://fileSaveInHere/dummy.anim";
# ------------ in fileDialog to save *.anim ------------
func _loadAnim(): #---loads-the-file-from-3.5
var config = ConfigFile.new();
var _err = config.load(convertPathLoad);
var animFile = config.get_value("Player1", "best_score"); #----ok
root1 = animFile;
return( animFile );
func _saveAnim():
var file = FileAccess.open(convertPathSave, FileAccess.WRITE);
file.store_var(root1);
func _on_file_dialog_file_selected(path):
convertPathSave = path; #---write the *.anim name in fileDialog save
_saveAnim();
it shows 27( dictionary ) not 18 anymore
var checkVarPath = "res://fileSaveInHere/1Jump.anim";
if ( buttonTypeOF.is_hovered() ):
if ( Input.is_action_just_pressed('mouse_button') ):
var file = FileAccess.open(checkVarPath, FileAccess.READ);
var content = file.get_var();
bbox.visible = ! bbox.visible;
if ( bbox.visible == true ):
$Label.text = (str(typeof(content))); #--shows-27------------
else:
$Label.text = ("");
had to convert the files 1 by 1
the rotation in degrees doesnt work anymore... it uses radians
this doesnt seem to work rad_to_deg
had to use this instead * (PI/180);
pt11_spr.rotation = root1.Fnum[animFrame].pt11.pa * (PI/180);
*.pa ( angle )
jonSS * (PI/180)
That converts degrees to radians. To convert radians to degrees, multiply by 180.0 / PI.
DaveTheCoder maybe its the rad_to_deg(PI) # Returns 180
- Edited
DaveTheCoder I don't know if that's a bug that will be fixed, or an intrinsic store_var/get_var incompatibility between Godot 3 and 4.
The decision has been made. The incompatibility will not be fixed.
https://github.com/godotengine/godot/issues/73530#issuecomment-1435792453