Hi there. Wanted to make sure I got this right before I did it. I’m wanting to persist my button toggle and variables across scenes using a global script. It seems for this current script it would mean cutting and pasting the lines prior to the ready function to the global script and then prepending the variable uses with the global script name? I’m not sure about the ready function as I may use the data differently in other menus so probably won’t be necessary to include in the global. Basically I want the choices in all 4 sub menus to persist while going between them. I may also display the results of each choice made in the sub menus to the main menu but haven’t decided yet. I’ve browsed a few of the options for persistent data and a global script seems to be the best option as I don’t need anything to persist outside of the session.
extends Control
var enviroatlas = preload("res://EnviroAtlas.tres")
@export var enviro = preload("res://enviro.tres")
var envdict = {"Aeternus":[0, 0, 5], "Diamond":[300, 0, 4], "Freedom":[600, 0, 1], "Insula":[900, 0, 8],
"Magmaria":[0, 200, 4], "Megalopolis":[300, 200, 2], "Pike":[600, 200, 8], "Rook":[900, 200, 8],
"Silver":[0, 400, 4], "Block":[300, 400, 6], "Wasteland":[600, 400, 7], "Discord":[900, 400, 5],
"Atlantis":[0, 600, 7], "ZhuLong":[300, 600, 6], "Anubis":[600, 600, 7], "Wagner":[900, 600, 6]}
func _ready() -> void:
for n in enviro.get_buttons():
n.toggled.connect(_enviropressed)
enviroatlas.region = Rect2(envdict[enviro.get_pressed_button().name][0], envdict[enviro.get_pressed_button().name][1], 300, 200)
$choice.texture = enviroatlas
$Envdiff.text = "Difficulty " + str(envdict[enviro.get_pressed_button().name][2])
func _enviropressed(toggled_on: bool) -> void:
if toggled_on:
enviroatlas.region = Rect2(envdict[enviro.get_pressed_button().name][0], envdict[enviro.get_pressed_button().name][1], 300, 200)
$choice.texture = enviroatlas
$Envdiff.text = "Difficulty " + str(envdict[enviro.get_pressed_button().name][2])
func _on_button_17_pressed() -> void:
get_tree().change_scene_to_file.call_deferred("res://Mainmenu.tscn")
func _on_button_pressed() -> void:
var envkey = envdict.keys()
var renv = envkey.pick_random()
for n in enviro.get_buttons():
if n.name == renv:
n.button_pressed = true