On Background Switch

API -

function yourEvent(user, string_message)

    if user == nil then 
        -- if user is nil, that means the bg was changed by a non-user
        -- (or manually by streamer via level select dropdown)
        log('the level has switched to: ' .. string_message);
    else
        log(user.displayName .. ' has switched the level to: ' .. string_message); -- changed via command
    end
    
    if string_message ~= 'forest' then --prevent infinite loop of event procing
    
        runCommand('!background forest nightbot'); 
        -- runs the background command to switch level as the broadcaster, but also passes along who issued the command as well.
        -- this is useful for making custom commands to allow viewers to switch levels and passing along the information that they issued it.
    end
end

return function()
    addEvent('backgroundSwitch', 'yourEvent'); -- attaches the event to yourEvent()
    keepAlive();
end

Events are asynchronous coroutines.

Last updated