Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Frostybros | |
Old Version | Published before Godot 3 was released. |
I am making a dialogue system for my game. I use clickable buttons to select dialogue. The problem is that when I release the button, it skips to the end of the dialogue as if the player kept pressing the first option. This is due to me using a variable called “stage” to determine what should happen upon button press. How can I fix this?
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):
print (str(stage))
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("Before you lies the night sky of New York.")
if stage == 1:
get_node("../../../World/CanvasLayer/PlayerSpeech/Button1/Option1").set_text("Close the blinds.")
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("The blinds have been closed.")
get_node("../../../World/CanvasLayer/PlayerSpeech/Button1/Option1").set_text("Open the blinds.")
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
if 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