![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | KaBOOM |
I’m making an app that allows the user to press a TextureButton corresponding to an overwatch character, and it redirects the user to a new page displaying the TextureButtons of other characters that are strong and weak to that character. i have all the data stored in a dictionary with arrays inside of arrays that are inside the dictionary keys, within a script called global.gd
The dictionaries looks like this:
var selected = TYPE_DICTIONARY
var Doomfist = {
"Stats": ["Doomfist", 250, 0],
"Counters": [
["Good Counter", "res://Buttons/dvaButton.tscn"],
["Good Counter", "res://Buttons/genjiButton.tscn"],
["Good Counter", "res://Buttons/reinhardtButton.tscn"]
],
"Countered": [
["Very Weak Against", "res://Buttons/sombraButton.tscn"],
["Very Weak Against", "res://Buttons/pharahButton.tscn"],
["Weak Against", "res://Buttons/mccreeButton.tscn"],
["Weak Against", "res://Buttons/orisaButton.tscn"],
["Weak Against", "res://Buttons/soldier76Button.tscn"]
]}
When one of the buttons in the main screen is pressed, this function is called:
func _on_doomfistButton_pressed():
global.selected = global.Doomfist
get_tree().change_scene("res://SoloResult.tscn")
When the button is pressed the “selected” variable is set to contain the same data as whatever is in the dictionary of the relevant hero, for example in this case selected would contain all the data within the doomfist dictionary.
The scene is then switched over to the results page, which contains two side-by-side 2 column wide grid containers inside of scroll containers. My goal is to display the button referenced in each array and then the text next to it, however i cannot get this to work.
Currently I’m doing this:
func _ready():
for counters in global.selected.Counters:
$Container/Counters/CtrGrid.add_child(global.selected.Counters[0][1])
I’m trying to add the buttons (which i have saved as scenes in “res://Buttons”) as nodes inside of the grid container, but i have no idea what i’m supposed to be doing.
Alternatively i could change the nodes i have inside the grid container (i created dummy nodes of the same type and size) into the nodes i referenced within the dictionary, but i also don’t know how i can do this.
TLDR: How can i import a scene into another scene through code, and how can i access the data within my dictionary? do i need to re-organise the dictionaries? (there’s 28 of them, so RIP)