Okay so I have a input set up, where the player can choose the button configuration. However this gets reset when the game is closed, and the player will have to do it again.
I want to save the new input action created by the player. To eliminate this need.
However I'm having trouble, as
A. Saving stores it as a string, Not a InputEvent
B. Loading as a string, fails when converting to an InputMap
Which results in this error
Invalid type in function 'action_add_event' in base 'InputMap'. Cannot convert argument 2 from String to InputEvent.
Here's the complete code for context:
func save_game(string_file = "user://data.sav"):
var file = File.new()
file.open(string_file,file.WRITE)
var data=[]
#Save Options
var options_data = {}
var op_input_data = {}
for i in InputMap.get_actions():
var input_actions = InputMap.get_action_list(i)
op_input_data[str(i)] = input_actions
options_data["Inputs"] = op_input_data
options_data["Level"] = Globals.get("v/current_level")
data.append(options_data)
#Save Game
var game_data = {}
data.append(game_data)
#print(data)
file.store_var(data)
file.close()
func load_game(string_file = "user://data.sav"):
print("Loading...")
var file = File.new()
file.open(string_file,file.READ)
#Load Options
var data = file.get_var()
var options_data = data[0]#To get the array index,
if options_data.has("Inputs"):#Inputs
for i in options_data["Inputs"]:
InputMap.add_action(str(i))
InputMap.action_add_event(i,i[0])
if options_data.has("Level"): #Current_level, Disable this if testing another level
var sav_level = options_data["Level"]
get_tree().change_scene(sav_level)
print(data)
#Load Game WIP
file.close()