Tymless Tutorial: Data



   
  < routines

Variables

 
local & global >
 

Drawing

Control

Data

Reference

 

A variable is a name tag to which we can assign a value. We can then retrieve the value later by referring to the variable name.

System variables are created by Tymless to hold information related to the turtle and the program itself. They all begin with a dollar character $ and may include other special characters.

You can also create your own 'user-defined variables'. These must start with a letter, but can contain any number of letters and numbers mixed together.

// a polygon with variable sides and colour
$r=1
numsides = ?: 10 + 2
${}=numsides
$h=numsides
{}

The random integer function ?: returns a random integer between 1 and 10 inclusive. This is assigned to variable numsides.

Variables are not limited to numbers. Then can also be assigned text, colours, locations, shapes, aliases and structures, with one important restriction: if the value is changed, the new value must be of the same type as the old. For example you cannot assign text to a number variable. The program will terminate with an error message.

name = "fred"
name = 2     // error. name is now a text variable

This email has been checked for all viruses at the internet level by MailDefender. MailDefender is powered by Sophos anti-virus (www.maildefender.net)
   
  < routines
 
local & global >