The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

I have three main nodes. The book cover, the book opened, and a next icon to flip.
When the player clicks on a recipe icon, the book cover overlay pops up.
I want to make it so that when the player clicks on the next icon, the image changes to book opened.
And if the player clicks next again, the overlay disappears and we return to the game.

onready var clicks = 0

func _ready():
    $DrDarlinCover.visible = false
    $DrDarlinOpened.visible = false
    $nextIcon/nextIcon.visible = false

func _on_recipeIcon_gui_input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT and event.is_pressed():
            $DrDarlinCover.visible = true
            $nextIcon/nextIcon.visible = true

func _on_nextIcon_gui_input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_LEFT and event.is_pressed():
            if clicks == 0: 
                $DrDarlinOpened.visible = true
                $DrDarlinCover.visible = false
                clicks += 1
            if clicks == 1:
                $DrDarlinOpened.visible = false

With this code, the book opened image never pops up, and we just return back to the game after book cover disappears.

I laboured at this for days, to no avail. Any help is greatly appreciated! Or if there's any feedback on how to simplify the code as well. Thank you!

Godot version 3.2
in Engine by (34 points)

1 Answer

0 votes
Best answer

Use elif or else in: if clicks == 1.

by (106 points)
selected by

Oh my gosh it's working. It's always the simplest things we fail to notice... Thanks so much friend. I really appreciate it. Cant' believe I've been racking my brain for days and failed to look at what's clearly wrong with the code.

Yes, it usually happens. I think the best thing sometimes is to rewrite the piece of code that seems to fail. I'm glad I helped.

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.