Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | LockManipulator |
Sprite
ScrollContainer
VBoxContainer
This is how I’ve got it laid out in EmailBox.tscn, the sprite is the background. I add nodes to VBoxContainer through code (script is attached to Sprite):
#EmailBox.gd
onready var email = preload("res://Email.tscn")
var i = 0
for item in GlobalVars.cur_player["email names"]: #for each item in this list
var email_button = email.instance()
var email_text = email_button.get_node("Label")
email_text.text = GlobalVars.cur_player["email contents"][i]
$ScrollContainer/VBoxContainer.add_child(email_button) #add node as child of vboxcontainer
i += 1
var empty_email = emptyemail.instance()
$ScrollContainer/VBoxContainer.add_child(empty_email) #because you can't see the last item in a scrollcontainer, adds empty item at the end to bump up the last item I want the user to see
Email.tscn is laid out like this:
Control
TextureButton
label
And the script attached to the top node of Email.tscn is
#Email.gd
extends Control
signal view_email
func _ready():
pass
func _on_Button_pressed():
emit_signal("view_email")
Basically, I want a bunch of control nodes (the node from Email.tscn) instanced. Each of those have a button. When the user clicks the button, I want to connect that to EmailBox.gd (the script attached to EmailBox.tscn). Also, does each instanced button have a different name? Because I want every button except the one that was clicked, freed. Adding in:
get_tree().get_current_scene().get_node("EmailBox/ScrollContainer/VBoxContainer/Control").connect("view_email", self, "view_email")
at the end of the for loop in EmailBox.gd and a function view_email() only makes the first instanced button call the function view_email(). I need them to all call view_email() and free all the other buttons that were not clicked.