Advanced Data Types

This AeroScript program shows how to use advanced data types, such as enumerations, structures, and arrays.

// Advanced Data Types Example:
// Demonstrates how to use enumerations, structures, and arrays.

// Define an enumerated type.
// If you do not specify integer values, enumerated values will be numbered
// automatically.
enum Quadrant
	None = 0
	One = 1
	Two = 2
	Three = 3
	Four = 4
end

// Define a structure containing built-in types.
struct Point
	$x as real
	$y as real
end

// Default a structure that contains a structure and an enumeration type.
struct PointInformation
	$point as Point
	$quadrant as Quadrant
end

// Define a string array that represents the names of the Quadrant enumeration.
var $QuadrantNames[] as string = ["None", "One", "Two", "Three", "Four"]


program

	// Declare a Point variable and initialize the values.
	var $myPoint1 as Point = [5.5, 10.2]

	// Declare a Point variable without initializing the values.
	var $myPoint2 as Point

	// Set the values in $myPoint2 manually.
	$myPoint2.x = -4.0
	$myPoint2.y = -5.4

	// Declare an array of a structure.
	var $pointsInfo[2] as PointInformation

	// Fill in the PointInformation structures.
	// Get the quadrant by passing the Point structures to a function and
	// getting the enumerated value in return.
	$pointsInfo[0].point.x = $myPoint1.x
	$pointsInfo[0].point.y = $myPoint1.y
	$pointsInfo[0].quadrant = GetQuadrant($myPoint1)
	$pointsInfo[1].point.x = $myPoint2.x
	$pointsInfo[1].point.y = $myPoint2.y
	$pointsInfo[1].quadrant = GetQuadrant($myPoint2)

	// Display the points and the quadrants.
	var $pointNum
	for $pointNum = 0 to (length($pointsInfo) - 1)
		PrintPointInformation($pointNum, $pointsInfo[$pointNum])
	end

end


// Function that demonstrates taking a structure as an argument and
// returning an enumeration.
function GetQuadrant($point as Point) as Quadrant
	var $quadrant as Quadrant

	if (($point.x == 0.0) || ($point.y == 0.0))
		$quadrant = Quadrant.None
	elseif ($point.x > 0.0)
		if ($point.y > 0.0)
			$quadrant = Quadrant.One
		else
			$quadrant = Quadrant.Four
		end
	else
		if ($point.y > 0.0)
			$quadrant = Quadrant.Two
		else
			$quadrant = Quadrant.Three
		end
	end

	return $quadrant
end


// Function that takes an enumerated type and looks up a string
// in an array variable.
// Note that enumerated types are represented as integers in AeroScript.
// This means that enumerations can be used as an integer type for purposes such as
// indexing into an array.
function QuadrantName($quadrant as Quadrant) as string
	var $name as string

	if (($quadrant < 0) || ($quadrant >= length($QuadrantNames)))
		$name = "Invalid Quadrant"
	else
		$name = $QuadrantNames[$quadrant]
	end

	return $name
end


// Function that prints information about a structure.
function PrintPointInformation($pointNumber as integer, $pointInfo as PointInformation)
	var $quadrantString as string
	var $pointString as string

	$pointString = "(" + RealToString($pointInfo.point.x) + ", " + RealToString($pointInfo.point.y) + ")"
	$quadrantString = QuadrantName($pointInfo.quadrant)

	AppMessageDisplay("Point " + IntegerToString($pointNumber) + " = " + $pointString + ", Quadrant = " + $quadrantString)
end