States
States define the flow of the rooomAssistant. You can define multiple states and jump between them. Actions can be executed when a state is entered or when a button is clicked. Via the API you can dynamically add new states, change the text of the speechbubble, add new buttons and modify the scene by moving the camera or playing animations.
states.add
Dynamically add a new state. The argument is an object with the following properties:
name
: name of the statespeechBubble
: object with the following properties:actions
: array of actions that will be executed when the state is entered
states.add(state?: Object): Promise<string>
api.states
.add({
name: 'extra', // name of the state
speechBubble: {
text: 'This is an new state.', // text of the speechbubble
// followed by an array of buttons
buttons: [
// button 1
{
text: 'Goto next state', // text of the first button
actions: [
// an array of actions that will be executed when the button is clicked
{ name: 'setState', arg: 'next' }, // here we jump to the state 'next'
{ name: 'cameraSetTarget', arg: [1, 2, 3] }, // here we set the camera target to xyz [1, 2, 3]
],
},
// button 2
{
text: 'Back to previous state', // text of the second button
actions: [{ name: 'setState', arg: '_back' }], // here we jump back to the previous state: '_back' is a special name
},
],
},
actions: [
// actions to be executed when the state is loaded
{ name: 'playAnimation', arg: 'hey' }, // play the animation 'hey' when the state is loaded
{ name: 'playAnimation', arg: ['idle', 3000] }, // play the animation 'idle' after 3000ms
],
})
actions: [
{
name: 'states.add',
arg: {
/* ... */
},
},
]
states.get
Get all settings of a state by name. If no name is provided, the current state will be returned. The result will be the state object.
GETstates.get(state?: string): Promise<Object>
api.states.get('myNewState').then((result) => console.log(result))
actions: [{ name: 'states.get', arg: 'myNewState' }]
states.set
Sets a state by name. The result will be the name of the set state.
SETstates.set(state?: string): Promise<string>
api.states.set('myNewState')
actions: [{ name: 'states.set', arg: 'myNewState' }]
states.getAll
Request all states. The result will be an array of all states.
GETstates.getAll(): Promise<Array>
api.states.getAll().then((result) => console.log(result))
states.delete
Delete a state by name. If no name is provided, the current state will be deleted. The result will be the name of the deleted state.
SETstates.delete(state?: string): Promise<string>
api.states.delete('oldState')
actions: [{ name: 'states.delete', arg: 'oldState' }]