How to Delay the UpdateEvent?

DEPARTD Posts: 4
edited August 2022 in Programming #1


I'm new to coding and I'm trying out a randomizer first. I have managed that by raising the eyebrows an update event starts and after a certain time, stops again, so that you get a random background image.

Next I would like to add an interval between the cycling through the images. But so far I have failed at all. My idea is to insert a delay into the updateFunc. But I can't find any solution. Do you have any Idea, how to do this?

// -----JS CODE-----
// @input int initialImage
// @input Component.Image image
// @input Asset.Texture[] texture
// @input float delayAfterStart = 0.1 {"widget":"slider", "min":0.0, "max":3.0, "step":0.01}
// @input float updateTriggerInterval = 0.2 {"widget":"slider", "min":0.0, "max":1.0, "step":0.01, "label": "Interval Time"}

// Get amount of Images
var imageAmount = script.texture.length;
var delayAfterTrigger = script.delayAfterStart;
var imagePass = script.image.mainPass;

// Updates Function every rendered Frame
var updateEvent = script.createEvent("UpdateEvent");

updateEvent.enabled = false;

// Set Initial Texture of a Screen Image
imagePass.baseTex = script.texture[script.initialImage];

// Start Randomize with Brow Raise
var startTriggerEvent = script.createEvent("BrowsRaisedEvent");

var stopRandomize = script.createEvent("DelayedCallbackEvent");

function randomizeStart(eventData) {
    updateEvent.enabled = true;
    startTriggerEvent.enabled = false;

// Random Number Function
function getRandomArbitrary(min, max) {
  return Math.floor(Math.random() * (max - min) + min);

// Update
function updateFunc(eventData)
    var randomNumber = getRandomArbitrary(0, imageAmount - 1);
    script.image.mainPass.baseTex = script.texture[randomNumber];

function stopFunc(eventData) {
    updateEvent.enabled = false;


  • Solved: I just created two DelayedCallbackEvents that executes each other alternately.