- Print
- DarkLight
- PDF
This section offers an overview of the programming fundamentals needed to start creating app scripts. The goal here is to get you up and running as quickly as possible, without having to learn a bunch of programming. You don't need to know much to start writing amazing scripts.
This single document will teach you everything you need to know. Anyone can do this - including you. Let's get started!
Variables
A variable is a placeholder for something (anything). In the world of programming, variables will contain one of the following things (aka types):
Type | Kind | Description |
---|---|---|
Number | Simple | Contains a numeric value (e.g. 64, 32, 15.32) |
Text | Simple | Also called a String; Contains a string of characters (e.g. 'Hello, world') |
Boolean | Simple | Contains the value true or false |
DateTime | Simple | Contains a date and / or time |
Null | Simple | An empty placeholder |
Object | Complex | Contains a larger concept or thing (see below) |
Let's see what this looks like in code:
// simple variable syntax
var age = 45;
var firstName = "Ethan";
var havingFun = true;
var dob = "05/16/1975";
// complex variable syntax (null for now; more on this later)
var car = null;
Each of these types are simple (except Object), meaning they just contain a simple value (like 45, true, or 'Ethan'). We call objects complex because they represent a larger, real-world concept or thing with their own set of simple characteristics.
Objects are powerful and arguably the most important concept in all of programming - not because they are difficult to understand, but because they are so flexible and allow us to model anything in the real or imaginary world. Let's look at those next.
Objects
In the world of programming, an object is a term used to represent almost anything. Any person, place, or thing is an object - basically any noun. A graph is simply a fancy word for a collection of connected objects.
You have already learned that the app runtime provides a set of objects (via its graph) that your scripts can use to enhance your apps. So, all you need to know is how to access and use these special objects.
Accessing an object is easy - you just type its name within your script. However, you will never just type the name by itself. Rather, you will type its name, followed by the name of a property or function you want to use. This means that in order to use any object, you simply need to know how to access an object's properties and functions. So let's learn those concepts real quick.
Properties
A property is simply an attribute of an object. They are simple adjective or noun-like characteristics of an object.
For example, a person (object) might have a first name, last name, and birthday (3 different properties).
Properties can be read-only, write-only, or both read and write. Let's look at the syntax for accessing properties.
// properties
// note: patient is an object and age is a property on that object
// get (read) the patient's age
var age = patient.age;
// set (write) the patient's age
patient.age = 55;
That's all there is to properties. Next up, we look at how to access an object's functions.
Functions
In programming, while objects represent the nouns of the world, functions represent the verbs - or the things we can do with objects. This relationship between objects and functions is important for you to remember.
A car is an object (noun) that can drive, which is a function (verb).
- Car = Object (Noun)
- Drive = Function (Verb)
When you write your own scripts, you will want to know what graph objects are available to you and what properties and functions each one has to offer.
Another important aspect of functions is that they can support zero or more input arguments. For example, let's say we have a calculator object with four basic functions (add, subtract, multiply, and divide). The add function will need to know which two numbers you want to add, right? This means that the function would need two input arguments.
// add two numbers together using a tools object
// we store the results inside a variable named 'sum'
var sum = tools.add(2, 3);
// display the results to the user
// note: alert is another function that takes a single input - what you want to display to the user in a popup window
user.alert(sum);
In this example, calculator is the object. Add is the function, which takes two inputs, each seperated by a comma. The function then does its calculation and returns the results to your variable named sum.
If you're feeling overwhelmed, don't worry - we're on the home stretch!
Events
An event is a programming term that refers to a moment when something happens that you might be interested in. For example, when a user clicks a button or presses a keyboard key, an event occurs (aka fires or triggers).
As programmers, when we subscribe to an event, this means we want the system to run our code when that specific event occurs.
When you create scripts for your apps, the App Builder product always requires that you choose an event for your script. This is how the runtime will know when to actually run your scripts. Refer to the events reference page for a list of all events supported by the runtime.
Debugging
Debugging is a programming term that refers to the process of watching a program under-the-covers, while it runs, in order to learn how it operates and troubleshoot any issues (aka bugs).
A debugger is a tool, used by programmers, to perform the task of debugging. The provided App Simulator includes a debugger to facilitate this process.
That's it! You have learned all the concepts needed to write your own scripts and make your apps powerful. If you still have questions, visit our forums or watch our video tutorials on this same material. Happy coding! =)