Make different images appear and disappear on button click, like flipping a book

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By amberlimshin

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!

:bust_in_silhouette: Reply From: Nitsuga

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

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.

amberlimshin | 2021-02-02 06:47

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.

Nitsuga | 2021-02-02 07:21