Tymless Tutorial: Data



   
  < colours

Structures

 
aliases >
 

Drawing

Control

Data

Reference

 

A structure is a variable which contains more than one item of data. Each item is held in a kind of 'sub-variable' called a property or subscript. A property is accessed via a name beginning with a dot; a subscript via a number (or numeric expression) beginning with an underscore.

ashape.name = "square"
ashape.index = 2
ashape_1 = $here
ashape_2 = bshape_1

Here variable ashape contains two properties .name and .index, and also two subscripts 1 and 2.

// program 3: output a random square number using an array
do 20
   squareno_$# = $# * $#
end
tell squareno_(?:20)

In this program, squareno is a structure containing an array of squares. A subscript can be:

  • a number
  • an expression in brackets which evaluates to a number
  • a variable containing a number (the variable can't be a structure)
  • a system variable holding a number
  • a hash # which refers to the last (largest) subscript in the array

Subscripts must be greater than zero, and will be rounded to the nearest whole number automatically.

Structures can also be created by assigning a list to the variable, e.g.

colourvalues = 1, 0, 0.5

The variable colourvalues now contains three subscripts. colourvalues_1 is 1, colourvalues_2 is 0, colourvalues_3 is 0.5

Some variables which are not user-defined structures will nevertheless contain system properties and subscripts, depending on the type of data they hold. A system property starts with dot dollar .$. For example, you can manipulate the various parts of a colour held in a variable through its system properties such as .$r ...

 

   
  < colours
 
aliases >