Cycle the output language
Updated
Pressing L steps an AI agent’s output language through the languages its AI Translation allows, then back to the original, and logs each change from subscribeOutputLanguage.
Click the scene, then press L to change the language. The dialog's language button follows. Translating replies needs the AI service; choosing the language does not.
Cycle the output language
#pragma lifecycle(startup, update, dispose)
let translator;let stopWatching;let index = -1; // -1 is the original language
function startup() { translator = findEntity('Guide').getComponent(AITranslatorComponent); try { const selection = translator.getOutputLanguage(); log('Allowed:', selection.allowedLanguages.join(', '), '· translation', selection.translationEnabled ? 'on' : 'off'); stopWatching = translator.subscribeOutputLanguage((now) => { log('Showing', now.translationEnabled ? now.effectiveLanguage : 'the original'); }); } catch (error) { log('No translation here:', error.message); translator = undefined; }}
function update() { if (!translator || !Input.keyboard.isKeyReleased(Key.L)) return; const languages = translator.getOutputLanguage().allowedLanguages; index = index + 1 < languages.length ? index + 1 : -1; if (index === -1) { translator.setTranslationEnabled(false); return; } translator.setOutputLanguage(languages[index]); translator.setTranslationEnabled(true);}
function dispose() { if (stopWatching) stopWatching();}How it works
Section titled “How it works”The script is explained step by step in Cycle the output language.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
LanguageCycle.xrproj