Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jump to a title using variables #350

Closed
NickHatBoecker opened this issue Oct 31, 2023 · 2 comments
Closed

Jump to a title using variables #350

NickHatBoecker opened this issue Oct 31, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@NickHatBoecker
Copy link

NickHatBoecker commented Oct 31, 2023

Hey guys, I'm developing a cozy game with a lot of dialogs. The player spends their summer vacation in a small town and can talk to the villagers, do quests, etc. Everyday the player should be able to choose a set of interactions with an NPC.

For example: Talk to NPC, ask to walk the dog or leave.

Example dialog:

~ npc_default

npc: Hello, dear. What's on your mind today?
- Talk
    ...some dialog...
- Walk the dog
    do spawn_dog()
    ....
- Leave => END


~ npc_day1

npc: This is your first day, huh?

It would be awesome if player chooses "Talk" to jump to the dialog for the current day.
I know that it's possible like this:

- Talk => npc_day1

But I would like to use a variable to set the current day, otherwise I would have to write a lot of if statements or use a mutation, right?

- Talk => npc_day{{GlobalStoreManager.current_day}}

Would this be possible to implement?
I don't know how the interpretation of variables in dialog lines works, but maybe you just add some helper function at this line?

@NickHatBoecker NickHatBoecker added the enhancement New feature or request label Oct 31, 2023
@Selenyhr
Copy link
Contributor

It indeed seems like a decent idea, but it would pose a few problems which could mess up your game in unintended ways, mostly due to the fact that this jump mechanism would be impossible to statically check, and so it could raise runtime errors that require debugging. Static errors are easier to debug, so I would not recommend to use this sort of feature :)

The way you'd do what you want easily, and with static debugging would be:

- Talk => npc_talk

~ npc_talk

if current_day == 1
	=> npc_day1
elif current_day == 2
	=> npc_day2
elif current_day == 3
	=> npc_day3
# ...
else
	=> npc_day_other

It has the added benefit of always providing a fallback, as well as being statically analyzed for error. This way you can never have the Dialogue Manager jump to an unknown title, because it would have warned you right in the editor which is way better developer experience.

Although I have to agree it's a bit unsightly with all these elifs :) Maybe #312 could help with readability for this kind of use case.

@nathanhoad
Copy link
Owner

For the same reasons Selenyhr mentioned, I'm reluctant to add variable jump labels. Once I find the time to implement a match statement that would be the best solution. Until then conditionals are the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants