Godot Version
Godot Version 4.2.1
Question
Hi. How can we save the user preferences if the ui node we used is option button (enum one) Please help…
Godot Version 4.2.1
Hi. How can we save the user preferences if the ui node we used is option button (enum one) Please help…
OptionButton
has a signal item_selected
which you can connect to and that will provide the connected callback with the index of the selected element.
To make the selection persist across restarts, save the index to a file and restore it when opening the scene again by setting the button’s selected
property to it.
I managed to save it by config file method.
Watch the youtube video above and in the end head up to the code where your options button (enum) node is placed.
Add these into func _ready():
var language_settings = ConfigFileHandler.load_language_settings()
language_select.selected = language_settings.language_id
# mine is language settings so I'm using language. Change variables which suit your preference
Then connect the node “selected” to the script. Then in it’s function, write:
func _on_language_select_item_selected(index):
ConfigFileHandler.save_language_settings("language_id",index)
# mine is language settings so I'm using language. Change variables which suit your preference
This will save the options button preferences into the .ini file and it will be loaded on game start.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.