Documentation ¶
Index ¶
- type ExecutionType
- type Function
- type Option
- func HandleEndDialogue(handler func(*VM)) Option
- func HandleEnterNode(handler func(*VM, string) ExecutionType) Option
- func HandleExitNode(handler func(*VM, string) ExecutionType) Option
- func HandleShowChoice(handler func(*VM, []string)) Option
- func HandleShowLine(handler func(*VM, string) ExecutionType) Option
- func RegisterCallback(function Function) Option
- type VM
- func (vm *VM) ChooseAndResume(selectedChoice int) error
- func (vm *VM) GetVariable(name string) (val asm.Value, exists bool)
- func (vm *VM) Reset()
- func (vm *VM) Resume() error
- func (vm *VM) Run() error
- func (vm *VM) SetVariableBoolean(name string, val bool)
- func (vm *VM) SetVariableNull(name string)
- func (vm *VM) SetVariableNumber(name string, val int)
- func (vm *VM) SetVariableString(name string, val string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExecutionType ¶
type ExecutionType int
ExecutionType tells the VM whether to suspend ot keep running after a callback is executed.
const ( // PauseExecution tells the VM to suspend PauseExecution ExecutionType = iota // ContinueExecution tells the VM to keep running ContinueExecution )
type Function ¶
type Function struct { // Func is the actual code which handles the events Func func(vm *VM, args ...asm.Value) ExecutionType }
Function is a callback for custom events fired with the Call instruction.
type Option ¶
Option is a builder-like function for instantiating a new VM
func HandleEndDialogue ¶
HandleEndDialogue assigns a handler for the EndDialogue event. Pass as an option to NewVM.
func HandleEnterNode ¶
func HandleEnterNode(handler func(*VM, string) ExecutionType) Option
HandleEnterNode assigns a handler for the EnterNode event. Pass as an option to NewVM.
func HandleExitNode ¶
func HandleExitNode(handler func(*VM, string) ExecutionType) Option
HandleExitNode assigns a handler for the ExitNode event. Pass as an option to NewVM.
func HandleShowChoice ¶
HandleShowChoice assigns a handler for the ShowChoice event. Pass as an option to NewVM.
func HandleShowLine ¶
func HandleShowLine(handler func(*VM, string) ExecutionType) Option
HandleShowLine assigns a handler for the ShowLine event. Pass as an option to NewVM.
func RegisterCallback ¶
RegisterCallback assigns a handler for a custom event which can be fired with the Call instruction.
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM is the virtual machine which runs the instructions generated by the dialogue tree.
func (*VM) ChooseAndResume ¶
ChooseAndResume will notify the VM that an option was selected and resumes from the decision point according to the option chosen. Which options are available are given by the ShowChoice event, which is fired at the decision point and puts the VM into a waiting state until an option is chosen.
func (*VM) GetVariable ¶
GetVariable retrieves a named variable saved by the StoreVariable instruction or by the SetVarableT() series of methods. If the variable does not exist, val is Null and exists is false.
func (*VM) Reset ¶
func (vm *VM) Reset()
Reset stops a VM and clears its variables so that the next time it runs, it will be as if running for the first time.
func (*VM) Run ¶
Run executes the program from its start point. Assigned variables are persisted across runs.
func (*VM) SetVariableBoolean ¶
SetVariableBoolean stores val as a boolean under the given name. Name strings are converted into symbol values. Saved variables are persisted across runs.
func (*VM) SetVariableNull ¶
SetVariableNull stores a null value under the given name. Name strings are converted into symbol values. Saved variables are persisted across runs.
func (*VM) SetVariableNumber ¶
SetVariableNumber stores val as a number under the given name. Name strings are converted into symbol values. Saved variables are persisted across runs.
func (*VM) SetVariableString ¶
SetVariableString stores val as a string under the given name. Name strings are converted into symbol values. Saved variables are persisted across runs.