Howdy I know how Undertales dev made all the text in a game in a huge list
I was wondering how he differentiates objects. what would the best-optimized way be besides running a bazillion events every second checking which object is talking?
ik this is kinda confusing I have work in 10 minutes so ill try to answer any follow up questions when free
I saw a YT video recently about how Undertale was made and how the dialogue is all contained in one huge if-statement. That must have been tough to keep track of.
In GDevelop a lot of people use Yarn, where all dialogue is contained within a JSON file and edited with the built-in Yarn editor. Then all you need is simple dialogue launch events, which might have conditions such as:
(1) Player is in collision with sally and (2) presses the X key.
(I tend to use ‘Player distance to sally is below 150 pixels’ rather than constant collision checks. I understand the distance check is more performant)
The action for this event would load the dialogue for the Sally NPC from the JSON file, based on a named dialogue node. This approach could be used for as many characters in your game as you like.
It gets a little more complicated if you want to track dialogue progress. The dialogue extension/Yarn itself can do this (‘save dialogue state’ action), but I haven’t tried that yet. I track dialogue with a structure variable called dialogueStage. The children of that variable are all the NPC names eg. dialogueState.sally. Each has a number. 0 = I haven’t spoken to that NPC yet. 1 = I have spoken to that NPC once. 2 = I have spoken to that NPC twice. And so on. I use these numbers in conditions to launch the appropriate dialogue so that an NPC will never say “We have never met before” twice, and can say things like “We spoke already today!”.
It gets a little more complicated still if you want to track the decisions players make during dialogue, if you intend to let the player choose responses eg.
Do you want cake?
Yarn can track decisions made during dialogue (‘save dialogue state’ again), but I haven’t tested that yet or got as far as coming up with other methods.
I hope some of that helps. In summary, you can have all your dialogue in one place and use very simple dialogue launch events for as many NPCs as you like.
If you haven’t used Yarn before and want to give it a try, I made a tutorial showing how to set up the basics.