Functions

A function is a set of commands that are grouped together and named so that they can be used more easily in your code. You should create a function if you need your program to do the same sequence of commands more than once. Using functions makes your code shorter and easier to manage.

Bitsbox has two kinds of functions: built-in functions and custom functions.

You use some of Bitsbox's built-in functions—like tap, touching, and drag—to tell your program what to do when the user interacts with the tablet. Other built-in functions—like loop—make your program do something even when no one's interacting with it.

Custom functions are… custom. You create them whenever you need them and call them whatever you like.

This code stamps a monster and plays a sound every time the user taps the screen. The function tap is built in to Bitsbox. The function draw is a custom function we wrote and named ourselves.