NPCS and Textboxes?

I don’t think I worded the title right but I don’t know how to make an NPC or Textbox and I’m hoping someone here could help somehow? Obviously I’m a beginner and I’ve tried for about 3 months looking for something to help me with this but it’s just the same tutorial of making a game like Snake or Tetris. I have a working game but really it’s just a guy walking around in a close space.

NPCs would simply be entities like the player, you should have a master Entity class that all sub-entities extend. Once you’ve added the relevant features to the NPC such as movement, triggers for when the player is close, then you can focus on the textboxes. The textboxes would probably be custom classes (or how I would do it). I’d probably store the possible messages the NPC can show in a way similar to the code below.


private String[] text = { "Hello there!", "Do you like pizza? Go find me some!", "Go away!" };

First I would show the first message if the player was nearby. If the player clicks on the message, it would show the next one and once all the messages have been shown, reset the counter to show the first message again.

Do not give every text box it’s own separate class. Make a text box class, and then load the dialog from an external file.

Exactly as Opiop said, although I didn’t mean for it to come across as I meant multiple custom textbox classes, sorry!

Sorry for responding so late but I actually don’t know how would I go about doing “triggers for when the player is close” I’m very new to this and I’ve honestly been struggling for years to find anything to learn from.

You need Dialog System with load text from custom file (XML, Yaml, etc…)
Dialog have stages (phases)
on every stage you have some NPC text and answers
*answers - may have some events like Have 100 gold, Male etc
**triger action (next dialog, summon dragon …)
**bool single time call
**bool show inactive (not have 100 gold) , but render in dialog

on exit dialog save current NPC stage and return to it or start dialog from Middle stage (after hello stage)