Game Development Reference
In-Depth Information
The differing types of information that can be stored in variables are called
data types . These include integers (whole numbers, e.g., 5), floating point
numbers (numbers with decimal values, e.g., 3.14), characters (a single
alphanumeric value), strings (words and texts, e.g., “hello”), Boolean values
(e.g., true and false), and other data types made from mixtures of the
aforementioned.
Variables don't just exist automatically in computer memory. They must be
declared . The process of declaring a variable gives it a name, initial value,
and a size. Some examples are shown in Listing 1.9 .
Listing 1.9 An Example of Declaring Variables of Differing
Types
var x: int = 10; //an integer called x with the value 10
var y: float = 5.6; //a float called y with the value 5.6
var isSpinning: boolean = true; //a Boolean value set to true
var ch: char = 'a'; // a character called ch with a value 'a'
// a string called myName with the value Penny
//Note: the datatype starts with a Capital “S”
var myName: String = “Penny”;
If you don't know what value should be placed into a variable you do not
need to assign one. For example,
var x: int;
will create an integer variable called x and the value will be set to 0
automatically.
Variables in computer memory can be conceptualized as boxes in a large
storage space. The different types of variables have different sized boxes. The
smallest box is a Boolean, as you only need to store a value of 1 or 0 inside it.
A character is the next size up. It would hold all the alphanumeric characters
such as those appearing on the keys of your keyboard and a couple of
miscellaneous others. The integer size box is even bigger, holding numbers
between 32,768 and 32,767 and a float box bigger again holding numbers
with seven decimal digits of significance between 0.000000 × 10 95 and
9.999999 × 10 96 . The exact size of the boxes will change depending on
operating system and computer processor, 3 but the relative sizes remain the
same. A conceptualization of memory allocation from variable declarations
is shown in Figure 1.25 .
3 If you are interested in exploring this topic more, see http: //en.wikipedia.org/wiki/
Primitive_data_type .
 
Search Nedrilad ::




Custom Search