You must be a Pro member to watch this episode.

Get Access Now

Sign in now if you're already Pro.


Build Some Buttons


Intro to Scripting


Building a Functional Timer


Intro to Scripting

Published by Chris Slowik

Episode Notes

Extra tips from the author

Adding scripts to your UI

Kite's method of attaching scripts to layers is very similar to the way Unity works. Each layer can have scripts connected to it as children. You can access properties of the layer and its children through the script. Javascript is the basis for the scripting language in Kite, and there's a pretty thorough documentation of the API on the Kite website.

We'll be adding a script to the button group to shuffle the Y positions of the children layers. Here's a quick function to shuffle an array, plucked from Stack Overflow:

function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;

  // While there remain elements to shuffle...
  while (0 !== currentIndex) {

    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;

    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;

  return array;

By attaching our script to an action that gets fired by the button click, we can shuffle our buttons whenever we want!

How to shuffle an array in javascript

Episode Topics: