Signal is not being emitted from scene to another scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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.

:bust_in_silhouette: Reply From: Okan Ozdemir

Hi,

you need to do this:

func _ready():

	OS.set_window_fullscreen(true)
	Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
#	print(OS.get_screen_size())
	print(1*9/4.7*2+6)
	get_node("Begin").connect("visibility_changed", self, "beginthere")
	get_node("Begin").emit_signal("visibility_changed")
#	
	#print(OS.get_user_data_dir())
	get_node("Begin").connect("gui_input", self, "Begin")
	get_node("Load").connect("gui_input", self, "Load")
	get_node("Saved_Games").connect("gui_input", self, "Saved_Games")
	get_node("ColorRect/go_to_main_menu").connect("gui_input", self, "go_to_mainmenu")
	
	get_node("Scenes").connect("gui_input", self, "_on_Scenes_gui_input")
	
	get_node("Quit").connect("gui_input", self, "Quit")
	
#	get_node("Scenes/ScenesPopupMenu").connect("id_pressed", self, "_open_levels")
	
	get_node(".").find_node(str("go_to_main_menu")).connect("pressed", self, "_on_LoadSaved_toggled", [false])
	
	yield(get_tree().create_timer(0.5), "timeout")
	
	Node_PauseMenu.show_message(String("Enhanced " + OS.get_name() + " experience"), 3)
	
	get_node(".").connect("tree_entered", Global_batch, "is_mainmenu_on", [1])
	emit_signal("tree_entered")
	
	get_node(".").connect("tree_exited", Global_batch, "is_mainmenu_on", [0])

See the last 2 lines of code above. The tree should be forced to emit signal when entered the tree emit_signal("tree_entered"). But when tree is out, you just connect it

Then in Global script:

func is_mainmenu_on(value):
	if value == 0:
		Global_batch.mainmenu_on_or_off = false
		print(mainmenu_on_or_off, "jjop")
		if get_node("/root/Node_PauseMenu").get_node("Notouchdevice"):
			get_node("/root/Node_PauseMenu").get_node("Notouchdevice").visible = true
	if value == 1:
		Global_batch.mainmenu_on_or_off = true
		print(mainmenu_on_or_off, "true")
		if get_node("/root/Node_PauseMenu").get_node("Notouchdevice"):
			get_node("/root/Node_PauseMenu").get_node("Notouchdevice").visible = false

See that. Even it was _ready() function but not emitted. Thanks