Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | eviking |
I am trying to emit a signal that connects to a separate scene.
I have three scripts that are processing a dialog box. I have my player “disabled” when he collides with the hit box to trigger the dialog box. When the dialog is finished, a signal is supposed to be emitted, which goes back and allows my player to start moving again.
Player script
extends KinematicBody2D
var active = true
var velocity = Vector2.ZERO
var roll_vector = Vector2.DOWN
export var ACCELERATION = 500
export var MAX_SPEED = 80
export var FRICTION = 500
export var ROLL_SPEED = 125
func _physics_process(delta: float) -> void:
var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO && active == true:
if input_vector.x > 0:
animationPlayer.play("WalkRight")
else:
animationPlayer.play("WalkLeft")
velocity = velocity.move_toward(input_vector * MAX_SPEED, ACCELERATION * delta)
else:
animationPlayer.play("Idle")
velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)
velocity = move_and_slide(velocity)
func _on_body_entered(body: Node) -> void:
active = false
MAX_SPEED = 0
func dialog_finished():
active = true
MAX_SPEED = 80
Dialog hit box script (same scene as player)
extends Area2D
const y = preload("res://UI/DialogeBox.tscn")
const z = preload("res://Player/Tom.tscn")
func _on_body_entered(body: Node) -> void:
if "Tom" in body.name:
var x = y.instance()
get_tree().get_root().get_node("World").get_child(2).add_child(x)
x.connect("dialogue_finished", self, "_on_dialog_finished")
# queue_free()
pass
func _on_dialog_finished():
print("done Talking")
var tomin = z.instance()
z.dialog_finished()
Dialog box object script (separate scene from the two above)
extends RichTextLabel
signal dialogue_finished
var dialog = [This is just testing text", "Is that your luggage?"]
var page = 0
func _ready() -> void:
set_bbcode(dialog[page])
set_visible_characters(0)
set_process_input(true)
func _input(event):
if Input.is_action_just_pressed("ui_accept"):
if get_visible_characters() > get_total_character_count():
if page < dialog.size()-1:
page += 1
set_bbcode(dialog[page])
set_visible_characters(0)
else:
emit_signal("dialogue_finished")
get_parent().queue_free()
elif get_visible_characters() < get_total_character_count():
set_visible_characters(get_total_character_count())
func _on_Timer_timeout() -> void:
set_visible_characters(get_visible_characters()+1)
So at the end of it all, I am able to get through my dialog, but I am stuck there as my player does not get his movement turned back on from the signal not being carried over or something. Sorry if this is a bit much, but thanks for any help.