godot_dialogue_manager icon indicating copy to clipboard operation
godot_dialogue_manager copied to clipboard

Match statements for dialogue

Open IntangibleMatter opened this issue 2 years ago • 2 comments
trafficstars

Is your feature request related to a problem? Please describe. In writing my dialogue, I frequently have dialogue that's based off of how many times you've talked to a character. Currently the only way to write dialogue to work like this is by having long if/elif/else statements.

Describe the solution you'd like Syntactic sugar over the if/else statement that lets you state the one variable you'd like to compare against at the start, followed by options for each of them, as an example.

match Chars.john_talk_count:
    0:
        John: Hey, nice to meet you!
    1:
        John: Hey, {{Chars.player_name}}, right? Good to see you again!
    2:
        John: Hey! I've already talked to you twice. Isn't that enough for now?
    _:
        John: {{Chars.player_name}}... please, we've talked {{Chars.john_talk_count}} times already... I need a break.
Chars.john_talk_count += 1

Which is way nicer and faster to write than:

if Chars.john_talk_count == 0:
    John: Hey, nice to meet you!
elif Chars.john_talk_count == 1:
    John: Hey, {{Chars.player_name}}, right? Good to see you again!
elif Chars.john_talk_count == 2:
    John: Hey! I've already talked to you twice. Isn't that enough for now?
else:
    John: {{Chars.player_name}}... please, we've talked {{Chars.john_talk_count}} times already... I need a break.
Chars.john_talk_count += 1

Describe alternatives you've considered Just having a bunch of if statements that check the same property verbosely

Additional context This would be a great addition for writing dialogue faster. It also means that if you want to change which variable is being checked, you only have to change the value in the match statement,

(please forgive me if this does exist, I'm new to using the plugin but I couldn't find this feature anywhere in the documentation)

IntangibleMatter avatar Oct 14 '23 09:10 IntangibleMatter

I've been thinking of adding match statements but it's not a small task - it's definitely on the todo list but I'm not entirely sure how long before I'll get to it.

nathanhoad avatar Oct 14 '23 10:10 nathanhoad

Noted, maybe I'll take a look at the parser and see if I can find a way to add them, save you a bit of work.

IntangibleMatter avatar Oct 14 '23 21:10 IntangibleMatter