This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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
in Engine by (164 points)
edited by

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?

1 Answer

0 votes
Best answer

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()
by (29,510 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.