Godot Version
4.6.3
Question
Hi! Sorry, I don’t know what keywords to use for this to search for previously answered questions.
I have a scene which I’ve set to autoload. I want another script to call the script attached to that scene. It works alright, but the scene in question is a UI, and it pops under my other UI when I show it by calling a function in the script.
I can get it to pop over all the other UIs by setting Z Index to 1, however, the buttons don’t work. (I’ve currently only hooked up the YES button up via a signal to the script for testing purposes)
(Side note, if you know a better way to divide the screen into a grid than just spamming hbox/vboxcontainers, I’d be happy to hear it lol)
I’d also like to take the result from the dialog box (be it YES or NO) and return that to the script from which we called the function so we can finalize the decision there. I don’t understand how to do that aside from just hooking up the signal from the button directly to a function in the receiving script but that seems like a bad solution.
Here’s the code for where I’m calling it from (the inventory page in my pause menu):
extends Control
@onready var item_list: VBoxContainer = $"Split/Left column/ScrollContainer/Item list"
@onready var mainpausemenu: Control = $"../mainpausemenu"
@onready var item_name: Label = $"Split/Right column/VSplitContainer/item name container/item name"
@onready var item_quantity: Label = $"Split/Right column/VSplitContainer/item quantity container/item quantity"
@onready var item_description: Label = $"Split/Right column/VSplitContainer/PanelContainer/item description"
@onready var sub_viewport: SubViewport = $"Split/Right column/VSplitContainer/SubViewportContainer/SubViewport"
@onready var sub_viewport_container: SubViewportContainer = $"Split/Right column/VSplitContainer/SubViewportContainer"
func _ready() -> void:
inventoryhandler.inventory_updated.connect(update_inventory)
func update_inventory():
# clear the list before updating it
for i in item_list.get_children():
item_list.remove_child(i)
i.queue_free()
# update the list
for i in inventoryhandler.inventory:
if i != null:
var instance = load(i["item_scene"]).instantiate()
# for every item in our inventory, make a button
var button = MenuButton.new()
button.text = instance.item_name
# then we add "use" and "drop" to the button's drop down menu
button.get_popup().add_item("Use")
button.get_popup().add_item("Destroy")
button.get_popup().id_pressed.connect(dropdown.bind(i["item_scene"]))
button.flat = false # (this is just for looks, personal preference)
# then we send all the data from the item to a function
# so when we mouse over the item (or enter focus with a gamepad)
# it'll update stuff in the right column with the data we provided here
button.mouse_entered.connect(right_column_info.bind(instance.item_description).bind(i["quantity"]).bind(instance.item_name).bind(i["item_scene"]))
button.focus_entered.connect(right_column_info.bind(instance.item_description).bind(i["quantity"]).bind(instance.item_name).bind(i["item_scene"]))
# this time we clear all the info whenever we're not mousing over anything
# (or moved focus to a different element with gamepad)
button.mouse_exited.connect(clearinfo)
button.focus_exited.connect(clearinfo)
# then we make the button actually visible on screen by
# assigning it as a child of the item list container
item_list.add_child(button)
# handle the "back" button
func inventory_back() -> void:
mainpausemenu.show()
hide()
# this is where we handle the data that is sent over by the buttons
func right_column_info(itemscene,itemname,itemquantity,itemdescription):
var instance = load(itemscene).instantiate()
sub_viewport.add_child(instance)
item_name.text = itemname
item_quantity.text = str(itemquantity)
item_description.text = itemdescription
# clear the info whenever we're not hovering over anything
func clearinfo():
var instance = sub_viewport.get_child(0)
sub_viewport.remove_child(instance)
item_name.text = ""
item_quantity.text = ""
item_description.text = ""
# 0 is the first item in the menu, so "use"
# 1 is the second, which is "destroy"
func dropdown(id,scene):
if id == 0:
var item = load(scene).instantiate()
item.use()
inventoryhandler.remove_item(scene,1)
if id == 1:
destroyitemconfirm.confirmation()
# remove the item if user answered YES, otherwise bail out
#inventoryhandler.remove_item(scene,1)
Here’s the code for the confirmation dialog:
extends Control
func confirmation():
show()
func yes_pressed() -> void:
print("yes")



