You are on page 1of 3

CS 8 REVIEWER

Lua
- is the programming language used to x = { y="Monday" } -- create table
develop the Corona SDK. print( x.y ) -- "Monday"
- The industry standard for game z = "Tuesday" -- assign a new value to property
"Tuesday"
programming.
print( z ) -- "Tuesday"
- Useful in creating various applications x.z = 20 -- create a new property
and games. print( x.z ) -- 20
- Consistent scripting language. print( x["z"] ) – 20

Variables – something that stores values. The following are valid variables:
 x
Statements- provides instructions on what  X
operations & computations need to be done.  ABC
 _abc
Variables - store the values of these  test_01
computations.  myGroup
Assignment - Setting a value into a variable. The following are invalid variables:
three kinds of variables:  function
 global  my-variable
 local  123
 table fields
The basic types of values that you'll deal with
global variable - can be accessed in every are the following:
scope and can be modified from anywhere.
 nil—It is the only type whose value
myVariable = 10 is nil.
print( myVariable ) -- prints the number 10  Boolean—The Boolean type has two
values, false and true.
Scope - used to describe the area in which a  Numbers—Represents real (double-
set of variables live. precision floating-point) numbers.
 String—A String is a sequence of
local variable - accessed from a local scope characters.
and usually called from a function or block of  Tables—A data structure in Lua.
code.  Functions—Known as first-class
values of Lua.
x = 10 -- global 'x' variable
local i = 1 associative array- an array that can be
while i <= 10 do indexed not only with numbers, but also with
local x = i * 2 -- a local 'x' variable for the while
block
strings or any
print( x ) -- 2, 4, 6, 8, 10 ... 20 other value, except nil.
i=i+1
end Expression
- something that has a value.
- can include numeric constants, quoted
strings, variable names, unary and binary
Table fields - are elements of the table operations, and function calls.
themselves.
arithmetic operators
Arrays - can be indexed with numbers and  +, -, *, /, %, and ^
strings or any value pertaining to Lua except
nil. Modulo (division remainder) operator:

Property - When the index is a string, m = 18%4


print(m) – 2 [1] = "Green",
[2] = "Blue",
Power of operator: [3] = "Yellow",
[4] ="Orange",
n = 7^2 [5] = "Red"
print(n) –49 }
print(colors[4])
Relational operators - always result in false
or true and ask yes-or-no questions. Another way of writing table constructor to build
arrays in a faster and convenient way:
 == tests for equality and the operator
 ~= is the negation of equality. colors = {"Green", "Blue", "Yellow", "Orange",
"Red"}
logical operators print(colors[4]) – Orange
- and, or, and not.
- All logical operators consider both false Populating a table
and nil as false and anything else as true. - Ways to populate a table is to start with
an empty table and add things to it one at
string concatenation operator a time
- is denoted by two dots ..
- It takes two strings as operands and myNumbers = {}
splices them together. for i = 1, 5 do
myNumbers[i] = i
print("Hello " .. "World") end
for i = 1, 5 do
myString = "Hello" print("This is number " .. myNumbers[i])
print(myString .. " World") end

length operator # Tables - are also used in what is known as


- measures the length of a string. object-oriented programming.
- The length of a string is simply the
number of characters in it.
- A character is considered as 1 byte.

Strings - may contain characters with Functions - deal with a particular type of
any numeric value, including embedded value are part of that value.
zeros.  value is called an object
 functions are called methods.

three ways to quote strings: display objects - Anything drawn to the


 with double quotes screen.
 with single quotes
 with square brackets. factory function- Display objects are created
by calling a function.
print("This is my string.")
Display properties:
print('This is another string.')
print('She said, "Hello!" ')  object.alpha - is the object's
opacity.
print([[Is it 'this' or "that?"]])  object.height- is in local
coordinates.
Tables
 object.isVisible- controls whether
- are the proprietary data structure in Lua.
the object is visible on the screen.
- represent arrays, lists, sets, records,
 object.isHitTestable - allows an
graphs, an so on.
object to continue to receive hit
- table in Lua is similar to an associative
events even if it is not visible.
array
 object.parent- is a read-only
property that returns the object's
colors = {
parent.
 object.rotation- is the current o none—Dynamic content scaling
rotation angle (in degrees). turned off.
 object.contentBounds - is a table o letterbox—Uniformly scales up
with properties xMin, xMax, yMin, content as much as possible
and yMax in screen coordinates. o zoomEven—Scales up content
 object.contentHeight - is the height uniformly to fill the screen,
in screen coordinates. while keeping the aspect ratio
 object.contentWidth is the width in o zoomStretch—Scales up
screen coordinates. content non-uniformly to fill
 object.width - is in local the screen and will stretch it
coordinates. vertically or horizontally.
 object.x specifies the x-position (in
local coordinates) of the object vector objects - another way of creating
relative to the parent. display objects.
 object.xOrigin specifies the x-
position of the object's origin relative Functions - can carry out a procedure or
to the parent's origin. compute and return values
 object.xReference defines the x-
position of the reference point
relative to the object's local origin.
 object.xScale - gets or sets the X
scaling factor.
 object.y - specifies the y-position (in
local coordinates) of the object
relative to the parent.
 object.yOrigin - specifies the y-
position of the object's origin relative
to the parent's origin.
 object.yReference - defines the y-
position of the reference point
relative to the object's local origin.
 object.yScale - gets or sets the Y
scaling factor

two ways to store object methods as


properties:
 dot operator (.)
 colon operator (:)

config.lua – where corona projects are


configured.

The following values should be used to scale


content:

width (number)—Screen resolution width of


the original target device
(in portrait orientation)

height (number)—Screen resolution height


of the original target device
(in portrait orientation)

scale (string)—Type of autoscaling from the


following:

You might also like