pub struct DialogueVm { /* private fields */ }Expand description
Runs one Dialogue, one event at a time.
Create it with Default, then alternate start and
resume as described in the module
documentation. The same VM can be reused for another run, or another
node, once the current dialogue is finished.
A DialogueVm holds the Dialogue at start but can be changed each time a
start is called.
Implementations§
Source§impl DialogueVm
impl DialogueVm
Sourcepub fn start(
&mut self,
dialogue: Dialogue,
name: impl Into<NodeName>,
) -> Result<DialogueEvent, VmError>
pub fn start( &mut self, dialogue: Dialogue, name: impl Into<NodeName>, ) -> Result<DialogueEvent, VmError>
Same as DialogueVm::start_with but with NoHost as host.
Sourcepub fn start_with<H: RepliqueHost>(
&mut self,
host: &mut H,
dialogue: Dialogue,
name: impl Into<NodeName>,
) -> Result<DialogueEvent, VmError>
pub fn start_with<H: RepliqueHost>( &mut self, host: &mut H, dialogue: Dialogue, name: impl Into<NodeName>, ) -> Result<DialogueEvent, VmError>
Start dialogue at the node name and run up to the first event.
The caller give a RepliqueHost to give access to its registered functions.
Fails with VmError::DialogueNotFinished if a run is still in
progress, and with VmError::DialogueNodeNotFound if the node does
not exist. Starting again after DialogueEvent::Finished is fine and
resets the VM.
Sourcepub fn vars(&self) -> &VarStore
pub fn vars(&self) -> &VarStore
Every variable the dialogue has written, and its value. Use for tests
Sourcepub fn resume(&mut self, resume: ResumeEvent) -> Result<DialogueEvent, VmError>
pub fn resume(&mut self, resume: ResumeEvent) -> Result<DialogueEvent, VmError>
Same as DialogueVm::resume_with but with NoHost as host.
Sourcepub fn resume_with<H: RepliqueHost>(
&mut self,
host: &mut H,
resume: ResumeEvent,
) -> Result<DialogueEvent, VmError>
pub fn resume_with<H: RepliqueHost>( &mut self, host: &mut H, resume: ResumeEvent, ) -> Result<DialogueEvent, VmError>
Answer the last DialogueEvent and run up to the next one.
The caller give a RepliqueHost to give access to its registered functions.
resume must match the event the VM emitted, see ResumeEvent. On
error the VM stays suspended where it was, so a wrong or out of range
answer can just be retried.