Calling the dialogue scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Melonad3


I watched a video about dialogue boxes and used a part of the code from it but it doesn’t seem to be working for me.
Like, the dialogue scene (Text.tscn) works fine by itself but while trying to call it from a different scene using my NPC, it doesn’t work.
I can’t seem to find the problem.
Thanks for the help!

extends Area2D
var active = false

const Dialog = preload("res://scenees/Text.tscn")

func _process(delta):
$Ping.visible = active
$Label.visible = active

func _on_NPC_body_entered(body):
if == 'Player':
	active = true

func _on_NPC_body_exited(body):
if == 'Player':
	active = false

func _input(event):
if Input.is_action_just_pressed("Interact") and active == true:

#Just checking if it works. As of now, it prints but doesn't call an instance of the scene
    $Label.visible = false
	$Ping.visible = false

	#should be calling the Text scene but its not

	var dialog = Dialog.instance()

I mean, there could be issues in the code (e.g. a typo like sceenes). It’s tough to figure out what’s going on here; perhaps there’s a debug message or something in the output window?

As an alternative, you could just instance the dialog in the scene itself and control its visibility via code. There’s little need to instance the scene here, imho.

spaceyjase | 2021-12-07 11:13

I’ll try to instance it in the main scene like you said then.
Thanks a lot!

Melonad3 | 2021-12-07 11:49

:bust_in_silhouette: Reply From: Inces

What do You mean Dialog works in its own separate scene ? Does it have any ready() function in which it obtains information where to show ? If not, I don’t see You setting global position of newly created Dialog instance. It propably works, but offscreen :slight_smile:

Ah i see
I put the dialogue scene in the main scene itself and am controlling it’s visibility. It seems to be working as intended for now!

Melonad3 | 2021-12-08 14:34

That is shorthand sollution :slight_smile:
Just do this there :

var dialog = Dialog.instance()
dialog.global_position = global_position

You just never told the DIalog to appear above NPCs head. You added dialog as a child of NPCs parent, so its default position was Vector2.ZERO, and You just didn’t see it on screen

Inces | 2021-12-08 14:41

Thanks a lot!

Melonad3 | 2021-12-08 15:15