Godot Version
v. 4.5.1.
Question
I am a newbie creating a mockup webpage game. I am trying to figure out how can I create a “Go Back” button. For now, I switch between pages by buttons located on them, that hide the current page and show another one, like so:
func _on_galeria_button_button_up() -> void:
$"..".visible = false
$"../../ObecnoscGaleria".visible = true
I wanted to make a separate button that would allow me to switch to the previous page. How do I make Godot recognize which page just got hidden? Sure, it knows to hide the one that’s “.visible = true”, but how can I make him recognize which of the “.visible = false” pages was the last one hidden?
It’s probably easiest to keep an array of pages the user visited. Then if they hit the back button, you simply go back in that array once, twice, however many times they press the back button.
Thanks! I am trying to wrap my head around it but I guess I just don’t know enough yet.
To my understanding, the only way to know the page was visited is to see if the “visible” changed from true to false. Could I ask you to help me figure out how could I implement this into an array?
I assume you have a signal connected to buttons which open a new page, that calls one of your functions.
The easiest way I can imagine this working is to simply add either an ID or the scene path itself to the array every time the user clicks any of the links.
Then later on, when the back button is pressed, you simply count backwards in the array and load back the scene that was in the previous index.
I wouldn’t bother checking the visible property at all, since in my opinion it’s a better idea to dynamically load / unload the scenes and pages anyway, otherwise you’ll fill up memory quite fast if those pages are too complex.