If you're not saving that state somewhere, you'll have to start. One option is to add an autoloaded script. This is a script that is loaded... wait for it... automatically - and is available from every other script. You could call it GameState.gd
or something. In that script you can have something like:
# GameState.gd
extends Node
var visited_levels = {
"level_1": false,
"level_2": false,
}
Once that is registered as an autoloaded script, you can use it like this:
#Level1
func _ready():
GameState.visited_levels.level_1 = true
Then, back to the original question, you could do something like:
func _ready():
$Button1.visible = GameState.visited_levels.level_1
$Button2.visible = GameState.visited_levels.level_2
Here you wouldn't need to create those extra functions because GameState.gd
already holds the boolean value you are looking for.