Need help setting up a dialog system that works for my needs

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

I’ve been hitting my head against a wall for the past three weeks trying to get around this problem. I don’t know coding but I’m learning as I go.

What I’m trying to achieve:
The player is a 2dKinimaticBody and has the ability to “inspect” items they run across. Like a point-and-click game but with keyboard clicks instead of a mouse. When the player goes up to a bookshelf and clicks the “inspect” key (the E key), a dialog box will appear and say something like, “yep, it’s a bookshelf, kinda boring.” Then when the player clicks on it again it says something different like, “Still a bookshelf”. And if the player continues to click on it, the second response will just recycle itself.

The problem:
I’ve tried most tutorials on how to build dialog boxes and they all work just fine… except they only work for 1 response since the input BBC text is in the actual dialog player node. Then usually the tutorial wraps up and I’m stuck with a working dialog box that only works for one thing. On the first scene of my game there are like 30-40 clickable objects to look at… am I supposed to build a dialog box for each and every item? each one formatting the dimensions, font, anchors for each one? I mean, if thats the answer then so be it…

However, what I would like to achieve is adding the dialog text directly to the bookshelf. Then, when a player clicks on the bookshelf, it sends the text to a single dialog box that then displays the text. That way I have 1 dialogbox group of nodes that I can save as a scene, instance into different scenes, and just save the text to each of the objects.

Is that even a thing? Can someone point me in the right direction at least? Someone who tried to help me said to bounce the dialog text from the area2d object to a singleton, then set up the dialog box to read the text off the singleton. I’ve tried and it doesn’t seem to work.

Pictures attached for clarity of my Node Tree, the script for my Dialog box, the script for the Area2d Bookshelf thing, and a script of my player just incase. I have a singleton set up but the only thing in there is - var Current_Dialog =

I’ve looked at a ton of YouTube tutorials (yes, even the GDQuest, Emilio, Kidscancode, and TheHappyCat)… I liked the happycat one but I couldn’t figure out how to do what I want as described above… and I even sat down to learn how to make a json file… but can’t find anywhere that tells me how to integrate it into godot. Or if they do I have the same problem I’ve always had where I need to build multiple text diolog systems. Even downloaded the “Godot Dialog System” from DaveTheDev and ran across the same problem of not being able to get it to play multiple instances of dialog.

mini-rant: I just don’t understand how you can have a game building engine that it’s so overly complicated to get a simple text dialog going. Man, I’m not even getting into branching dialog yet and this is already kicking my butt.

Node Tree
Dialog Box Script
Area2d Script
KinimaticBody Script

:bust_in_silhouette: Reply From: njamster

am I supposed to build a dialog box for each and every item?

Hell no!

what I would like to achieve is adding the dialog text directly to the bookshelf.

extends StaticBody2D

export (Array, String, MULTILINE) var dialogue

var first_time_interaction = true
func interact():
	if first_time_interaction:
		if dialogue[0]:
			first_time_interaction = false
		if dialogue[1]:

So each bookshelf instance will be a StaticBody2D (bookshelves don’t move, right?) with an array of multiline strings called dialogue and a boolean variable that will change on the first_time_interaction with that instance.

For that interaction it includes a method called interact that will print the first entry in the dialogue-array (if there is any) when first_time_interaction is true or the second entry in the dialogue-array (if there is any) else.

Note that dialogue is an export variable, so you can set it directly from the node inspector, no need to write code for that (you can though, if you want).

When the player goes up to a bookshelf and clicks the “inspect” key (the E key), a dialog box will appear

extends KinematicBody2D

# ...    

func _physics_process(delta: float):
	# ...

	if Input.is_action_just_pressed("ui_inspect"):
		for  body in $InteractionArea.get_overlapping_bodies():
			if body.has_method("interact"):

	# ...

This assumes that the player-node has an Area2D-child called “InteractionArea” with a CollisionShape that specifies how close an object has to be in order to be interactable. Now when the player presses “ui_inspect” we will query that area to get an array of all overlapping bodies. We step through this array until we arrive at a node that has an interact-method. Then we call that method and break the loop. This ensures that the player has to be near the object that triggers the dialogue and only one dialogue is triggered if multiple objects are in reach at the same time.

To keep things concise I simply printed the dialogue to the output console instead of using a dialog-box, it should give you the general idea though.

You are an amazing person and if it’s at all possible, I hope you have your favorite dessert with dinner tonight. You’re explanation and examples are awesome and really helped me out. I was able to follow along with what you said and I’ll play around with this immediately.

Thank you for seeing past my frustration, I really appreciate this. As someone who is learning code as I go it annoyed me when people ask questions and the response is a link to the Godot technical documentation… which for someone like me, reads like stereo instructions. I know those documents are speaking to me but I need a Rosetta stone to crack the translations, lol.

I don’t expect people to hand over exactly what I need, or for the Godot engine to read my mind and just instant gratify my needs, but the problem I was having was confusing and just making this whole experience of learning something a drag. You really raise my spirits today, I can’t thank you enough.

Noodle13 | 2020-05-29 15:45