API Reference & Tips

API - Reminders, Helpful tips, and things you should know before starting.

Press F5 to reload and replay scripts while Stream Avatars is connected!

To view the console log, focus Stream Avatars, and press Alt+C, then type: Lua After hitting enter, a console logger will come up showing you the logs. Once it is open, you can close the command input by pressing Alt+C again.

You can close the console log by repeating this process.

Do's and Don'ts

function anotherFunction()
    --see how this function is above the return function()?
    
    --the double dash is how we make line comments in lua scripting
    
    --[[
        this is how we make block comments in lua scripting.
        multiple lines. woooo
    ]]
    
    log('hello world');
end

return function()
    anotherFunction();
    --this should be the last function of your script! 
end --Don't put anything below the last end

Pre-existing Functions and Data

With LUA scripting in stream avatars, there are some addons your your script behind the scenes that you should know about!

return function()
    local a = { someData = 'hi', otherData = { 1, 2, 3 }};
    --some data table...
    
    local makeItString = json.serialize(a);
    --convert a to a JSON string
    
    log(makeItString);
    --prints the data structure.
    
    local b = json.parse(makeItString);
    --parse the string back into a table
    
    log(b['someData']); --prints hi
    
    
    --DO NOT TRY TO SERIALIZE NON-ARRAYS ALONG SIDE OF ARRAYS!
    local h = { };
    h[1] = 'hey'; --h is array
    h[2] = 'dont'; --h is array
    h['example'] = 'do'; --h is not array
    h['example2'] = 'this'; --h is not array
    local j = json.serialize(h); --stop! this breaks.
    
    --instead option 1:
    local k = { };
    k[1] = 'hey'; --k is array
    k[2] = 'DO'; --k is array
    k[3] = { }; --k is array
    k[3]['example'] = 'do'; --k is array
    k[3]['example2'] = 'this'; --k is array
    local l = json.serialize(k); --works
    
    --instead option 2:
    local m = { };
    m['n'] = { };
    
    m['n'][1] = 'hey';  --m is not array
    m['n'][2] = 'DO';  --m is not array
    m['example'] = 'do'; --m is not array
    m['example2'] = 'this'; --m is not array
    local o = json.serialize(m); --works
    
    
    
end

Last updated