how to simplify this code?
it become way to long there a way to simplify it?
basically i wan to make character selection or loading save/load slot, i make 10 empty dict, if i click slot_1
it well check ifplayer_dict_1
empty or not, if empty create new one, if it fill with dict , it will load and start game.
what i want to do is when i click 1 out 10 checkbox, it will check if i have data in player_dict
, if my player_dict
is empty, creation window will instance, if player_dict
not empty i can start game using player_dict
data from slot i choose.
func _ready() -> void:
for checkbox in get_tree().get_nodes_in_group("character_checkbox"):
checkbox.connect("pressed",self,"checkbox_data",[checkbox.get_name()])
the different between this two statement is
1 -"player_slot1"
i have 10 playerslot
2 - PlayerGlobalStat.player_dict_1
also have 10 playerdict_ in autoload
3 - slot_id
i want to update it when i click the right slot slot1 = slotid 1
this code below just 2 out 10, i need to repeat 8 more, it bcome way to long. i wonder there anything that can make it bit short
func checkbox_data(checkbox):
if get_node(player_slot_path + checkbox).name == "player_slot1":
if PlayerGlobalStat.player_dict_1.empty () == true: # if dict in dict_1 empty
slot_id = 1 # help change dict in player global
start_button.disabled = true # then close able create button
create_button.disabled = false # then open able create button
delete_button.disabled = true
get_node("slection_Panel/VBoxContainer/HBoxContainer2/create_delete/create").grab_focus()
else:
PlayerGlobalStat.current_player_data = PlayerGlobalStat.player_dict_1
start_button.disabled = false # then open able create button
create_button.disabled = true # then close able create button
delete_button.disabled = false
else:
pass
if get_node(player_slot_path + checkbox).name == "player_slot2":
if PlayerGlobalStat.player_dict_2.empty () == true: # if dict in dict_1 empty
slot_id = 2 # help change dict in player global
start_button.disabled = true # then close able create button
create_button.disabled = false # then open able create button
delete_button.disabled = true
get_node("slection_Panel/VBoxContainer/HBoxContainer2/create_delete/create").grab_focus()
else:
PlayerGlobalStat.current_player_data = PlayerGlobalStat.player_dict_2
start_button.disabled = false # then open able create button
create_button.disabled = true # then close able create button
delete_button.disabled = false
else:
pass