I have a VBoxContainer node named "side_buttons_left", with 3 children named "0", "1", "2" and "3".
These children start out as Blank Control nodes, but Should be replaced by the appropriate scenes in the parent's script.
The "side_buttons_left" scene is supposed to become a sidebar for up to 4 player-choosable accessibility buttons
(I'm building a prototype with developer-chosen buttons).
The error "Invalid get index 'controls_side_buttons' (on base: 'Dictionary')." stops the game whenever I enter the level,
or try to press the editor's play button when I'm in the level.
The error appears in the "side_buttons_left" scene's script on line 30:
extends VBoxContainer
const BUTTON_SCENE_JUMP_LOW = "res://scenes/ui/play_controls/side_buttons/jump_low.tscn"
const BUTTON_SCENE_JUMP_MEDIUM = "res://scenes/ui/play_controls/side_buttons/jump_medium.tscn"
const BUTTON_SCENE_JUMP_HIGH = "res://scenes/ui/play_controls/side_buttons/jump_high.tscn"
const BUTTON_SCENE_PAUSE = "res://scenes/ui/play_controls/side_buttons/pause.tscn"
export (bool) var on_left_side = true
# Button Types: 0=None, 1=jump_low, 2=jump_medium, 3=jump_high, 4=pause
var button_3_type = 0
var button_2_type = 0
var button_1_type = 0
var button_0_type = 0
func _ready(): print("#######################################################")
func _process(_delta):
print("###########################################")
print($".".visible)
# Assign Button Type values based on Settings in config.gd
if on_left_side:
button_0_type = config._settings["controls_side_buttons"]["left_0"]
# The above line is the erroneous line
# Invalid get index 'controls_side_buttons' (on base: 'Dictionary')
button_1_type = config._settings["controls_side_buttons"]["left_1"]
button_2_type = config._settings["controls_side_buttons"]["left_2"]
button_3_type = config._settings["controls_side_buttons"]["left_3"]
else:
button_0_type = config._settings["controls_side_buttons"]["right_0"]
button_1_type = config._settings["controls_side_buttons"]["right_1"]
button_2_type = config._settings["controls_side_buttons"]["right_2"]
button_3_type = config._settings["controls_side_buttons"]["right_3"]
# Make Invisble when No Buttons Set
if button_0_type == 0 and button_1_type == 0 and button_2_type == 0 and button_3_type == 0:
$".".visible = false
else:
$".".visible = true
# Assign Buttons based on Button Type values
if button_0_type == 0: $"./0".visible = false
else:
$"./0".visible = true
if button_0_type == 1: $"./0".change_scene(BUTTON_SCENE_JUMP_LOW)
elif button_0_type == 2: $"./0".change_scene(BUTTON_SCENE_JUMP_MEDIUM)
elif button_0_type == 3: $"./0".change_scene(BUTTON_SCENE_JUMP_HIGH)
elif button_0_type == 4: $"./0".change_scene(BUTTON_SCENE_PAUSE)
if button_0_type == 1: $"./1".visible = false
else:
$"./1".visible = true
if button_1_type == 1: $"./1".change_scene(BUTTON_SCENE_JUMP_LOW)
elif button_1_type == 2: $"./1".change_scene(BUTTON_SCENE_JUMP_MEDIUM)
elif button_1_type == 3: $"./1".change_scene(BUTTON_SCENE_JUMP_HIGH)
elif button_1_type == 4: $"./1".change_scene(BUTTON_SCENE_PAUSE)
if button_2_type == 0: $"./2".visible = false
else:
$"./2".visible = true
if button_2_type == 1: $"./2".change_scene(BUTTON_SCENE_JUMP_LOW)
elif button_2_type == 2: $"./2".change_scene(BUTTON_SCENE_JUMP_MEDIUM)
elif button_2_type == 3: $"./2".change_scene(BUTTON_SCENE_JUMP_HIGH)
elif button_2_type == 4: $"./2".change_scene(BUTTON_SCENE_PAUSE)
if button_3_type == 0: $"./3".visible = false
else:
$"./3".visible = true
if button_3_type == 1: $"./3".change_scene(BUTTON_SCENE_JUMP_LOW)
elif button_3_type == 2: $"./3".change_scene(BUTTON_SCENE_JUMP_MEDIUM)
elif button_3_type == 3: $"./3".change_scene(BUTTON_SCENE_JUMP_HIGH)
elif button_3_type == 4: $"./3".change_scene(BUTTON_SCENE_PAUSE)
The above "side_buttons_left" scene's script interacts with the "config" singleton ("res://scripts/autoload/config.gd").
This is that "config" singleton script:
extends Node
const USER_CONFIG_PATH = "user://config.cfg"
var _config_file = ConfigFile.new()
var audio_bus_names = ["music", "sfx"]
var _settings = {
"audio_volume": #in db
{
"music": AudioServer.get_bus_volume_db(
AudioServer.get_bus_index("music") ),
"sfx": AudioServer.get_bus_volume_db(
AudioServer.get_bus_index("sfx") )
},
"controls_side_buttons":
{
"left_0": 0,
"left_1": 0,
"left_2": 0,
"left_3": 0,
"right_0": 0,
"right_1": 0,
"right_2": 0,
"right_3": 0
} }
func _ready():
# warning-ignore:return_value_discarded
file_load(USER_CONFIG_PATH)
for i in audio_bus_names:
AudioServer.set_bus_volume_db (
AudioServer.get_bus_index(i),
config._settings["audio_volume"][i]
)
func _fixed_process():
var error_load = config.load(USER_CONFIG_PATH)
if error_load != OK:
config.set_value("audio_volume", "music", 0)
config.set_value("audio_volume", "sfx", 0)
config.save_file(USER_CONFIG_PATH)
func file_save(filepath):
var save_config = File.new()
save_config.open(filepath, File.WRITE)
save_config.store_line(to_json(_settings))
save_config.close()
func file_load(filepath):
var save_config = File.new()
if ( save_config.file_exists(filepath) ):
save_config.open(filepath, File.READ)
_settings = parse_json( save_config.get_line() )
save_config.close()