Not sure why the code block works wrong. I apologize in advance.
I have this game where i would like to keep track of the dialogs that have been played in order to give the player a "item"/"key" or show a new dialog.
I managed to make dialogs appear and disappear by creating buttons.
I would like that once the X button is pressed, the button will emit the visual dialog (this is working atm), and write itself inside a list that is located on a Global singleton (in order to keep a track of the texts.
The global.gd has a var called Data shown below
var Data = {
"Texts" : []
}
The objective of this "item" would be to keep a track of which dialog has already been played in order to: show a new dialog, open a new room.
My code for the button trying to get the "item" to appear on the global list
extends Button
var mouse_enter = false
var clickable = true
# Called when the node enters the scene tree for the first time.
func _ready():
$".".connect("mouse_entered", self, "_mouse_entered")
$".".connect("mouse_exited", self, "_mouse_exited")
func _process(delta):
if !$".".get_overlapping_areas():
clickable = true
func _mouse_entered():
Input.set_custom_mouse_cursor(Global.mouse_click)
mouse_enter = true
func _mouse_exited():
Input.set_custom_mouse_cursor(Global.mouse_norm)
mouse_enter = false
func _unhandled_input(_event):
if Input.is_action_just_pressed("mouse_click") and mouse_enter == true and clickable == true:
Global.Data["Texts"].append(self.name.capitalize())
_mouse_exited()
print(Global.Data["Texts"])
get_parent().get_node("ItemList").add_icon_item(self.texture)
Global.save_data()
self.queue_free()
My code for the scene that has the button and emits the signal (simplified)
extends Node2D
Dialogs
func unpause():
get_tree().paused = false
func onFarmer0pressed():
if getnodeornull('DialgNode') == null:
get_tree().paused = false
var dialog = Dialogic.start('Farmer0')
dialog.pausemode = Node.PAUSEMODE_PROCESS
dialog.connect('timeline_end', self, 'unpause')
add_child(dialog)
getnode("Farmer0").queuefree()
func onFarmer1pressed():
if getnodeornull('DialgNode') == null:
gettree().paused = false
var dialog = Dialogic.start('Farmer1')
dialog.pausemode = Node.PAUSEMODEPROCESS
dialog.connect('timelineend', self, 'unpause')
addchild(dialog)