nathanhoad / godot_dialogue_manager

A powerful nonlinear dialogue system for Godot
MIT License
2.1k stars 165 forks source link

Randomised jump-and-return #573

Closed DinosaurHorseSword closed 2 months ago

DinosaurHorseSword commented 4 months ago

Is your feature request related to a problem? Please describe. When writing dialogue, I only use jump-and-return statements and sometimes have random snippets. Currently, the parser return from the snippet it took and then evaluates again the siblings until all blocks have been reached. The current solutions either break the chain of jump-and-return or are tedious to write and difficult to read.

~ dialogue
before
% =>< snippet_0
% =>< snippet_1
% =>< snippet_2
after
=> END!
# outputs before, snippet_0/1/2 and each  following sibling, after

Describe the solution you'd like Parity with randomized jump, the jump-and-return solution should output the same as the jump.

~ dialogue
before
% => snippet_0
% => snippet_1
% => snippet_2
after
=> END!
# outputs "before, snippet_0/1/2, after"

Describe alternatives you've considered Two work-arounds, one that breaks the chain of jump-and-return:

~ dialogue
before
% => snippet_0
% => snippet_1
% => snippet_2

~ dialogue_next
after
=> END!

~ snippet_0
0
=> dialogue_next

~ snippet_1
1
=> dialogue_next

~ snippet_2
2
=> dialogue_next

And the other, that is less readable and requires to have an autoload:

# autoload.gd
var rdm: int
var rng: RandomNumberGenerator = RandomNumberGenerator.new()

# dialogue resource
~ dialogue
before

set rdm = rng.randi_range(0, 2)
if rdm == 0:
    =>< snippet_0
elif rdm == 1:
    =>< snippet_1
elif rdm == 2:
    =>< snippet_2

after
=> END!
nathanhoad commented 4 months ago

Yeah randomised jump-and-returns should behave the same as jumps so that's currently a bug.