API | Glossary

Here are definitions of some key terms that appear in the documentation.

For more complete information on any topic, refer to the excellent w3schools Web site, or any of the reference works listed on the Links page.

 

array

An array lets you store multiple values in a single variable. They are written as a list of comma-separated values, enclosed by square brackets.

Any JavaScript data type can be stored in an array, including other arrays.

// EXAMPLES:
// An empty array

var a = [];

// An array containing three numbers

var a = [ 2, 42, -5 ];

// An array containing many different value types,
// including an array

var a = [ 3.14159, [ 5, 7, 9, 11 ], "rabbit" ];

Each value in an array is called an element. Array elements are numbered sequentially, beginning with zero (0). They are referenced by writing the name of the variable containing the array, followed by the indexed location of the element enclosed in brackets.

var stooges = [ "Moe", "Larry", "Curly" ];

In this example, stooges[0] contains the string "Moe", stooges[1] contains "Larry" and stooges[2] contains "Curly".

JavaScript offers many functions for manipulating arrays.

 

clamp

A value is clamped when its range is forcibly restricted.

Example: RGB color components are expressed as integers in the range 0 to 255 inclusive. Commands that accept color components as parameters, such as PS.color(), clamp the values passed in these parameters to prevent errors. If you specify a color component as a number less than zero, PS.color() will silently changes the value to zero before using it. Values greater than 255 are changed to 255.

 

constant

A constant is a value that is not supposed to change. They are usually defined by assigning the value to a global variable.

var MONTHS = 12;

By convention, the names of constants are written in all upper-case letters to make them easy to distinguish.

JavaScript has no way "lock" a variable's value so that it cannot be altered. It's your responsibility to make sure you don't assign new values to constants!

Perlenspiel provides constants for many common values, such as PS.ERROR and PS.COLOR_BLACK. The Constants page lists them all.

 

float

A float is a positive or negative number with a fractional component.

1.619 and -3.14159 are floats. 42 and -13 are not.

In JavaScript, all numeric values (including integers) are actually stored and manipulated as floats.

 

floor

A value is floored when it is rounded down to the nearest integer.

Consider this list of values:

Flooring any of these numbers would result in the value 3.

All Perlenspiel functions that expect integer parameters use flooring to eliminate fractional values that might cause errors.

 

integer

An integer is a positive or negative number without a fractional component.

0, 1, -42 and 802,701 are integers. 1.619 and -3.14159 are not.

In JavaScript, all numeric values (including integers) are actually stored as floats.

 

object

JavaScript objects let you store multiple values as named properties of a single variable. They are written as a list of comma-separated property : value pairs, enclosed by curly brackets.

Any JavaScript data type can be stored in an object, including other objects.

// EXAMPLES:
// An empty object

var obj = {};

// An object containing three numeric properties
// named r, g and b

var obj = { r : 32, g : 128, b : 192 };

// An object containing four named properties
// with different value types

var obj = {
 name : "Mario",
 job : "plumber",
 age : 42
 friends : [ "Luigi", "Princess Peach" ]
};

Object properties are referenced by writing the name of the variable containing the object, followed by the name of a property, connected by a period (with no intervening spaces).

var crew = {
 captain : "Kirk",
 engineer : "Scotty",
 doctor : "McCoy"
};

In this example, crew.captain contains the string "Kirk", crew.engineer contains "Scotty" and crew.doctor contains "McCoy".

Objects offer an extremely powerful way to encapsulate data and functionality, making your code cleaner, more reusable and easier to debug.