Skip to content

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 state
  • speechBubble: object with the following properties:
    • text: text of the speechbubble. This can be a string or an object where the key is the language and the value is the text in that language. More information about the language can be found here.
    • buttons: array of buttons. More information about the buttons can be found here.
  • actions: array of actions that will be executed when the state is entered
GET states.add(state?: Object): Promise<string>
js
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
		],
	})
js
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.

GET states.get(state?: string): Promise<Object>
js
api.states.get('myNewState').then((result) => console.log(result))
js
actions: [{ name: 'states.get', arg: 'myNewState' }]

states.set

Sets a state by name. The result will be the name of the set state.

SET states.set(state?: string): Promise<string>
js
api.states.set('myNewState')
js
actions: [{ name: 'states.set', arg: 'myNewState' }]

states.getAll

Request all states. The result will be an array of all states.

GET states.getAll(): Promise<Array>
js
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.

SET states.delete(state?: string): Promise<string>
js
api.states.delete('oldState')
js
actions: [{ name: 'states.delete', arg: 'oldState' }]