SafeNarrativeWriter class

SafeNarrativeWriter

A protective wrapper around a sentence writer function that avoids writing the same sentence twice in a row. Useful for ensuring idempotent behavior in systems where duplicate instructions can be sent (e.g. during turn-based loops).

Key Responsibilities:

  • Prevent repeated visual or audio rendering of identical sentences
  • Ensure only new or changed sentences are passed to the delegate writer
  • Track last written sentence in memory

Usage Example:

final writer = SafeNarrativeWriter((s) => chatBox.write(s));
await writer.write(sentence); // writes only if not same as previous

Constructors

SafeNarrativeWriter(Future<void> _delegate(BaseNarrativeModel sentence))
Constructor

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reset() → void
Manually clears the last recorded sentence.
toString() String
A string representation of this object.
inherited
write(BaseNarrativeModel sentence) Future<void>
Writes a sentence only if it differs from the last one.

Operators

operator ==(Object other) bool
The equality operator.
inherited