Godot Version
Godot 4.3
Question
So these 8 buttons are tied to some boolean values I keep on another script. if those values are false I want them to be gray. if they are true I want them to be red. Everytime you press the button it inverts whatever that value was.
For some reason the only style that doesnt work is the grey-non-pressed one. I dont know if its a problem with godot not drawing the button until i click it or something else. Here’s the whole script. Thanks in advance:
extends Control
@onready var grid_container:GridContainer = $Panel/VBoxContainer/MarginContainer/GridContainer
const GREY = preload("res://styles/grey.tres")
const GREY_PRESS = preload("res://styles/grey_press.tres")
const RED = preload("res://styles/red.tres")
const RED_PRESS = preload("res://styles/red_press.tres")
var buttons:Array
var current_char = 0
func _ready() -> void:
visible = false
buttons = grid_container.get_children()
for i in range(min(8, buttons.size())):
buttons[i].pressed.connect(func(): on_button_pressed(i))
update_buttons()
func _process(delta: float) -> void:
if Input.is_action_just_pressed("open_chars"):
visible = !visible
update_buttons()
if Input.is_action_just_pressed("left"):
current_char -= 1
if current_char < 0: current_char = 33
update_buttons()
if Input.is_action_just_pressed("right"):
current_char += 1
if current_char > 33: current_char = 0
update_buttons()
func update_buttons():
for i in 8:
var button : Button = buttons[i]
var normal_style = RED if Main.chars[current_char].bosses[i] else GREY
var pressed_style = RED_PRESS if Main.chars[current_char].bosses[i] else GREY_PRESS
button.add_theme_stylebox_override("normal", normal_style.duplicate())
button.add_theme_stylebox_override("hover", normal_style.duplicate())
button.add_theme_stylebox_override("pressed", pressed_style.duplicate())
button.add_theme_stylebox_override("hover_pressed", pressed_style.duplicate())
#button.flat = !Main.chars[current_char].bosses[i]
$Panel/VBoxContainer/MarginContainer2/Label.text = Main.chars[current_char].name
Saver._save()
func on_button_pressed(button_index: int):
Main.change(current_char, button_index)
update_buttons()