Why isn't my CheckButton working/affecting in other scripts? (Godot 3.0 Beta2)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HarryCourt
:warning: Old Version Published before Godot 3 was released.

I’ve been stumped on this for hours.

I have a check box, and what I expect to happen is that when the checkbox shows “On”, the player can open a menu, where they can place they’re own objects into. If it’s “Off”, they cannot use the menu no longer. But this is not the case, even though it prints that it is indeed set off, it doesn’t change it at all.

Spawn Menu.gd:

    extends Control
    
    onready var text = get_node("Panel/ItemText")
    onready var devMode = get_node("/root/Scene/Player/Menus/Pause Menu/DevCheckButton").get("devCheckBox")
    
    func _ready():
    	self.hide()
    
    func _process(delta):
    	#self.set_position(player)
    	
    	if (Input.is_action_just_pressed("ui_spawnMenu") && devMode == true):
    		self.show()
    		
    	elif (Input.is_action_just_pressed("ui_spawnMenu") && devMode == false):
    		self.show()
    		
    	elif (Input.is_action_just_released("ui_spawnMenu")):
    		self.hide()
    	
    
    func _on_Button_mouse_entered():
    #	text.set_text(objectScene)
    	pass # replace with function body

Development Button.gd:

extends CheckButton

var devCheckBox = true

func _ready():
	print(is_pressed())
	pass
	


func _on_DevCheckButton_pressed():
	
	if (self.is_pressed()):
		devCheckBox = true
		
	else:
		devCheckBox = false

onready var devMode = get_node("/root/Scene/Player/Menus/Pause Menu/DevCheckButton").get("devCheckBox")

Note: you can replace .get("devCheckBox") by .devCheckBox.

Also, is _on_DevCheckButton_pressed even called?

Zylann | 2018-01-19 13:52

:bust_in_silhouette: Reply From: Zylann

Your Spawn Menu.gd will never get the current value of devCheckBox, because it only initializes it once and never gets it again from the source.

I changed your code:

extends Control

onready var text = get_node("Panel/ItemText")
onready var checkBoxNode = get_node("/root/Scene/Player/Menus/Pause Menu/DevCheckButton")

func _ready():
    self.hide()

func _process(delta):
    #self.set_position(player)

    var devMode = checkBoxNode.devCheckBox

    if (Input.is_action_just_pressed("ui_spawnMenu") && devMode == true):
        self.show()

    elif (Input.is_action_just_pressed("ui_spawnMenu") && devMode == false):
        self.show()

    elif (Input.is_action_just_released("ui_spawnMenu")):
        self.hide()