Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Frostybros | |
Old Version | Published before Godot 3 was released. |
I am working on a dialogue system for my game. I am making it that the player and intractable objects have Area2Ds around them. I connected the Players area to the object area with area_enter, and changes a var called caninteract to true. The problem is that connecting it like that makes me interact with the interactable that is highest in the scene tree, no matter which area was entered. I could connect from the object to my player, but storing the information for every single dialogue in the game in one script would be hellish. What should I do? Here’s the code if that helps.
extends Area2D
var caninteract = false
var stage = 1
func _ready():
set_fixed_process(true)
get_node("../../../World/CanvasLayer/PlayerSpeech/Button1").connect("pressed", self, "on_button1_pressed")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button2").connect("pressed", self, "on_button2_pressed")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button3").connect("pressed", self, "on_button3_pressed")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button4").connect("pressed", self, "on_button4_pressed")
func _fixed_process(delta):
if caninteract == true:
if Input.is_action_pressed("Interact"):
caninteract = false
get_node("../../../World").set_isinteracting(get_node("../../../World").isinteracting + 1)
get_node("../../CanvasLayer/Panel/NPCSpeech").set_text("The curtains partially cover the window.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button1/Option1").set_text("Open the curtains.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button2/Option2").set_text("Walk away.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button3/Option3").set_text("...")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button4/Option4").set_text("...")
# Dialogue Tree.
if stage == 1:
get_node("../../CanvasLayer/Panel/NPCSpeech").set_text("The curtains partially cover the window.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button1/Option1").set_text("Open the curtains.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button2/Option2").set_text("Walk away.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button3/Option3").set_text("...")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button4/Option4").set_text("...")
if stage == 2:
get_node("../../CanvasLayer/Panel/NPCSpeech").set_text("Before you lies the night sky of New York.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button1/Option1").set_text("Close the curtains.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button2/Option2").set_text("Walk away.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button3/Option3").set_text("...")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button4/Option4").set_text("...")
func on_button1_pressed():
if stage == 1:
stage = 2
elif stage == 2:
stage = 1
func on_button2_pressed():
if stage == 1 or stage == 2:
get_node("../../../World").set_isinteracting(get_node("../../../World").isinteracting - 1)
func on_button3_pressed():
pass
func on_button4_pressed():
pass
func _on_Player_Interact_area_enter( area ):
caninteract = true
func _on_Player_Interact_area_exit( area ):
caninteract = false