0 votes

(Beginner)

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 body.name == 'Player':
    active = true

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

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

#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()
    get_parent().add_child(dialog)`
in Engine by (17 points)
edited by

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.

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

1 Answer

0 votes

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 :)

by (5,557 points)

Ah i see
Thanks!
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!

That is shorthand sollution :)
Just do this there :

var dialog = Dialog.instance()
get_parent().add_child(dialog)`
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

Thanks a lot!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.