Skip to main content
Version: Current

Experimental Actions

  • experiment.beginRecording(options?: RecordingOptions): Promise<void>

    Starts a new recording. Returns a promise that resolves when recording has started. The returned promise will throw an error if recording could not be started. Reasons for this include insufficient permissions and not having a microphone.

    The first parameter is optional and is a RecordingOptions and is the options that should be used for the recording. Defaults to: { audio: true, video: true, screen: false }

    Examples
    Record for 10 seconds and download the files.
    await experiment.beginRecording({
    audio: true,
    video: true,
    screen: false
    });
    await os.sleep(10000);
    const data = await experiment.endRecording();
    let index = 0;
    for(let file of data.files) {
    os.download(file.data, `file-${index}`);
    index += 1;
    }
    Record the screen with microphone audio.
    await experiment.beginRecording({
    audio: ['microphone'],
    video: false,
    screen: true
    });
    await os.sleep(10000);
    const data = await experiment.endRecording();
    let index = 0;
    for(let file of data.files) {
    os.download(file.data, `file-${index}`);
    index += 1;
    }
  • experiment.createStaticHtmlFromBots(bots: Bot[], templateUrl?: string): Promise<string>

    Creates a HTML file that, when loaded, will display the given bots in a static version of CasualOS.

    Returns a promise that resolves with a string containing the HTML file. Resolves with null if the HTML file could not be created.

    The first parameter is a Bot[] and is the bots that should be displayed in the static version of CasualOS.

    The second parameter is optional and is a string and is the URL that the static HTML template file can be found at. If omitted, then the template from the server will be used.

    Examples
    Create a static HTML file and download it.
    const bots = getBots(inDimension('home'));
    const html = await experiment.createStaticHtmlFromBots(bots);
    await os.download(html, 'static.html');
  • experiment.endRecording(): Promise<Recording>

    Stops the recording that is in progress. Returns a promise that resolves with the recorded data.

    Examples
    Record for 10 seconds and download the files.
    await experiment.beginRecording({
    audio: true,
    video: true,
    screen: false
    });
    await os.sleep(10000);
    const data = await experiment.endRecording();
    let index = 0;
    for(let file of data.files) {
    os.download(file.data, `file-${index}`);
    index += 1;
    }
  • experiment.getAnchorPointPosition(bot: Bot, dimension: string, anchorPoint: BotAnchorPoint): object

    Gets the absolute position in the given dimension that the center of the given bot would be placed at if the bot was using the given anchor point.

    The first parameter is a Bot and is the bot that the anchor point position should be calculated for.

    The second parameter is a string and is the dimension that the anchor point position should be calculated in.

    The third parameter is a BotAnchorPoint and is the anchor point that should be calculated. Can be any valid #anchorPoint value.

    Examples
    Get the top anchor point of the current bot in the "home" dimension.
    const point = experiment.getAnchorPointPosition(bot, "home", "top");
    os.toast(point);
    Get the back right anchor point of the current bot in the "home" dimension.
    const point = experiment.getAnchorPointPosition(bot, "home", [ 0.5, -0.5, 0 ]);
    os.toast(point);
    Place bots at each of the anchor points.
    let points = [
    'top',
    'bottom',
    'front',
    'back',
    'left',
    'right',
    'center',
    ];

    for(let point of points) {
    let pos = experiment.getAnchorPointPosition(bot, os.getCurrentDimension(), point);
    create({
    space: 'tempShared',
    color: 'green',
    [os.getCurrentDimension()]: true,
    [os.getCurrentDimension() + "X"]: pos.x,
    [os.getCurrentDimension() + "Y"]: pos.y,
    [os.getCurrentDimension() + "Z"]: pos.z,
    anchorPoint: 'center',
    targetAnchorPoint: point,
    scale: 0.1,
    });
    }
  • experiment.getVoices(): Promise<SyntheticVoice[]>

    Gets the list of synthetic voices that are supported by the system. Returns a promise that resolves with the voices.

    Examples
    Toast the list of voices that are supported.
    const voices = await experiment.getVoices();
    os.toast(voices);
    Get the first US English voice.
    const voices = await experiment.getVoices();
    const usEnglish = voices.find(v => v.language === "en-US");
    os.toast(usEnglish);
  • experiment.localFormAnimation(bot: (string | Bot), animation: (string | number)): LocalFormAnimationAction

    Locally plays the given animation on the given bot.

    If an animation is already playing, it will be interrupted. When the given animation is finished playing, the interrupted animation will be restored.

    The first parameter is a (string | Bot) and is the Bot or Bot ID that the animation should be played on.

    The second parameter is a (string | number) and is the name or index of the animation that should be played.

    Examples
    Play the "jump" animation on this bot.
    experiment.localFormAnimation(this, "jump");
  • experiment.localPositionTween(bot: (string | Bot), dimension: string, position: object, options?: TweenOptions): Promise<void>

    Locally plays a tween that moves the given bot in the given dimension to the given position. Optionally allows customizing the easing of the tween.

    Returns a promise that resolves when the tween is finished.

    While the tween is playing, any updates to the bot's position and rotation are ignored. Once the tween is done playing, any change to the bot will reset the position/rotation.

    The first parameter is a (string | Bot) and is the bot or ID of the bot that should be tweened.

    The second parameter is a string and is the dimension that the bot should be tweened in. Note that the tween will only work if the given dimension is currently in the grid portal or miniGridPortal.

    The third parameter is a object and is the position that the bot should be tweened to. If you exclude a dimension (like x , y , or z ), then it will remain unchanged.

    The fourth parameter is optional and is a TweenOptions and is the options that should be used.

    Examples
    Tween the bot to X = 10 in the `home` dimension.
    experiment.localPositionTween(
    this,
    'home',
    {
    x: 10,
    });
    Tween the bot over 5 seconds.
    experiment.localPositionTween(
    this,
    'home',
    {
    x: 10,
    },
    {
    duration: 5
    });
    Tween the bot with quadratic easing.
    experiment.localPositionTween(
    this,
    'home',
    {
    x: 10,
    },
    {
    easing: {
    type: 'quadratic',
    mode: 'inout'
    }
    });
  • experiment.localRotationTween(bot: (string | Bot), dimension: string, rotation: object, options?: TweenOptions): Promise<void>

    Locally plays a tween that rotates the given bot in the given dimension to the given rotation. Optionally allows customizing the easing of the tween.

    Returns a promise that resolves when the tween is finished.

    While the tween is playing, any updates to the bot's position and rotation are ignored. Once the tween is done playing, any change to the bot will reset the position/rotation.

    The first parameter is a (string | Bot) and is the bot or ID of the bot that should be tweened.

    The second parameter is a string and is the dimension that the bot should be tweened in. Note that the tween will only work if the given dimension is currently in the grid portal or miniGridPortal.

    The third parameter is a object and is the rotation that the bot should be tweened to in radians. If you exclude a dimension (like x , y , or z ), then it will remain unchanged.

    The fourth parameter is optional and is a TweenOptions and is the options that should be used for the tween.

    Examples
    Tween the bot 90 degrees around the Z axis in the `home` dimension.
    experiment.localRotationTween(
    this,
    'home',
    {
    z: Math.PI / 2,
    });
    Tween the bot for 5 seconds.
    experiment.localRotationTween(
    this,
    'home',
    {
    z: Math.PI / 2,
    },
    {
    duration: 5
    });
    Tween the bot with quadratic easing.
    experiment.localRotationTween(
    this,
    'home',
    {
    z: Math.PI / 2,
    },
    {
    easing: {
    type: 'quadratic',
    mode: 'inout'
    }
    });
  • experiment.speakText(text: string, options?: SpeakTextOptions): Promise<void>

    Speaks the given text using a synthetic voice and options. Note that this is a local effect. The gererated sounds are only played in the current session.

    Returns a promise that resolves when the text has been spoken.

    The first parameter is a string and is the text that should be spoken.

    The second parameter is optional and is a SpeakTextOptions and is the options that should be used to speak the text.