Building on from my experiment with visualising wordpress posts in Amazon Sumerian, I’ve begun to use State Machine Signals to store global variables and trigger other scripts in response to programatic events.
This is done by assigning a State Machine to an Entity that you’d like to be interactive, then setting up two states with assigned scripts. The first state’s script saves a variable globally and calls an onSuccess() function, that triggers the second function to execute.
Step 1
Step 2
Step 3
I’ve posted this scripts below (with comments) so you can now begin using State Machine Signals and scripts to organise your scene’s behaviour within Amazon Sumerian. Enjoy! 😀
getBlogPosts.js
// import that preview version of the Sumerian Scripting API as a variable called 's' import * as s from 'module://sumerian-common/api'; // A statement to Sumerian to expect SIGNALS export const SIGNALS = { // stating onSuccess as a signal to end the script when wordpess posts have been retrieved onSuccess: { description: 'Wordpress posts have been retrieved' } }; export default async function(ctx, options) { // get wordpress posts window.posts = await getPosts(); // once the script has stopped ctx.onStop(() => { // send the onSuccess signal ctx.signal(options.onSuccess); }); } // get posts from wordpress function getPosts() { let response = fetch('https://jamesmiller.blog/wp-json/wp/v2/posts') .then(response => { return response.json(); }); return response; }
postLoop.js
// import that preview version of the Sumerian Scripting API as a variable called 's' import * as s from 'module://sumerian-common/api'; export default async function(ctx, options) { // log posts that have been declared in getBlogPosts.js console.log(window.posts); }