Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

boolean value only works once and then stops

so im using godot and im trying to set up a button to switch between fullscreen and not, and when i run it and click the button it switches to fullscreen but then it decides to not want to switch back
code below:


extends Button

var on = false

func _on_FullScreen_pressed():
    if on == true:
        on = false
        OS.window_fullscreen = false
        $Label.text = "Fullscreen: No"

    if on == false:
        on = true
        OS.window_fullscreen = true
        $Label.text = "Fullscreen: Yes"

i assume the problem is happening because i set on to false in the top if statement, then in the bottom if statement reads it as false and sets it back
if that is the case please provide me with a way to fix

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

extends Button

var on = false

func _on_FullScreen_pressed():
    if on == true:
        on = false
        OS.window_fullscreen = false
        $Label.text = "Fullscreen: No"

    else:
        on = true
        OS.window_fullscreen = true
        $Label.text = "Fullscreen: Yes"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading