Hello! I am very new to Godot and have recently run into a roadblock in the game I'm creating. Essentially, I have a level editor, in which the user can select a song, and the level data itself is saved to a .JSON file. It creates a folder with the level name in the directory chosen by the user, saves the .JSON, and copies the song file into the folder. Unfortunately, while it works fine-ish on Windows, it doesn't work whatsoever on Android. I've attempted to debug this and have spent the past week looking up solutions, but to no avail. Any help would be greatly appreciated, but I completely understand if I'm a dumbass and beyond saving. (Keep in mind that a lot of this code was written at like 2 A.M., so I hardly understand it myself. Hours of looking through forums and whatnot will do that to you!)
Here is the code in which I am having problems. It is stripped of (most) debugging & fluff such that it is only the needed parts.
extends Node
@onready var file_dialog: FileDialog = $"../SongFile/FileDialog"
@onready var export_dir: FileDialog = $ExportDir
@onready var export_progress: ProgressBar = $ExportingProg/ExportProgress
@onready var exporting_prog: ColorRect = $ExportingProg
@onready var debug: Label = $ExportingProg/ExportingDebug
var LevelData = {} ## Removed info, unneeded
func save(dir):
var base_dir = dir + "/"
DirAccess.make_dir_recursive_absolute(base_dir)
var level_name = LevelController.LevelData["Level Info"]["Name"] ## Gets the name from the .JSON
var LVLDIR = base_dir + level_name ##LVLDIR is the folder that it creates
DirAccess.make_dir_recursive_absolute(LVLDIR) ## No idea what this does, but it works
# Copy song, this is where I'm having problems
var SongCopy = file_dialog.get_current_path()
var file_name = SongCopy.get_file()
var dest_path = LVLDIR + "/" + file_name ## This just saves it to the folder created earlier
var source_file = FileAccess.open(SongCopy, FileAccess.READ) ## Gets the song
if source_file == null:
print("Failed to read song!")
return
var data = source_file.get_buffer(source_file.get_length()) ## Not sure what this does, but it's necessary.
source_file.close()
var file = FileAccess.open(dest_path, FileAccess.WRITE)
if file == null:
print("Failed to write song!")
return
file.store_buffer(data) ## Saves it I think
file.close()
# Save JSON
## This part is almost completely fine. I don't have any issues here
var path = LVLDIR + "/LevelData.json"
var JSON_string = JSON.stringify(LevelController.LevelData, "\t")
var json_file = FileAccess.open(path, FileAccess.WRITE)
if json_file:
json_file.store_string(JSON_string) ## no way that's crazy it saves the file
json_file.close()
func _on_export_dir_dir_selected(dir: String) -> void:
var base_dir = dir+"/"
save(dir) ## Runs the save function. That's where I'm having my problems
func _on_pressed() -> void:
export_dir.visible = true ## This shows the file directory. Not sure if this is the best way to do it but it works for me
await export_dir.dir_selected