How to use a button to change scene and change the text of a label in the new scene

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

So I know how to script a button to change scenes:
func _on_Button1_pressed():
get_tree().change_scene(“res://screens/Screen3.tscn”

And I know how to script a button to change a variable:
func _on_StarButton1_pressed():
button_choice = 1

And I know how to use a script to change the text in a label:
text = “Do you understand?”

But what I can’t figure out is how to do all three at the same time.

On one screen in my game (call it ScreenA), I offer 4 buttons and each takes the player to the same new screen (call it ScreenB) that features a label whose text I want to change according to the choice of button made on the previous screen. The scripts of those buttons each change the scene to ScreenB and set the variable “button_choice” to either 1, 2, 3, or 4 depending on the button pressed.
Now:
How do I get the Label script on ScreenB to find and use the value of variable
of “button_choice” made on ScreenA? I’m guessing it has something to do with get_node() but I can’t figure out how to call up the data from those previous buttons.

Here’s a sample script for the Label on ScreenB; I just need to know how to call the variable “button_choice”:

extends Label

func _ready():
get_node(“???”).get_variable(“button_choice”)
if button_choice == 1:
text = “Yes”
elif button_choice == 2:
text = “No”
elif button_choice == 3:
text = “Maybe”
elif button_choice == 4:
text = “Probably Not”

I have tried a variety of ideas for replacing the ??? but nothing so far works. There has to be a straightforward way to do this, I am just too much of a newbie to figure it out.
Thanks in advance for any suggestions/solutions you may offer.

:bust_in_silhouette: Reply From: MitchReidNZ

Check out https://forum.godotengine.org/1883/transfering-a-variable-over-to-another-scene

The general approach seems to be storing state to share between scenes in an auto-loaded singleton.