Appendix A

Lua Scripting References

In Hour 11, we introduced you to the programming language Lua and provided a brief overview of its foundational concepts. This appendix includes a few additional Lua reference tables and concepts that you may find useful as you begin to study the language.

Modifying Properties That Are Data Type and Enumerations

Data types are the different types of data a variable can store. They are listed in Tables A.1 and A.2.

TABLE A.1 Primitive Lua Data Types

Data Type

Description

Nil

No data.

Boolean

Data is either true or false.

number

Data is real numbers.

string

Data is an array of characters.

function

Data is a method written in C* or Lua.

userdata

C* data.

thread

Data is independent threads of execution.

table

Arrays, symbol tables, sets, records, graph, trees, and so on.

Table A.2 Roblox Lua Data Types

Data Type Categories

Custom Roblox Data Types

Colors

BrickColor, Color3, ColorSequence, ColorSequenceKeypoint

Position or Area Related

Axes, CFrame, UDim, UDim2, Rect, Region3, Region3int16

Number and Sequence

NumberRange, NumberSequence, NumberSequenceKeypoint

Connections and Events

RBXScriptConnection, RBXScriptSignal

Vectors

Vector2, Vector2int16, Vector3, Vector3int16

Classes

Instance

Enumeration Related

Enum, EnumItem, Enums

Other Types

DockWidgetPluginGuiInfo, Faces, PathwayPoint, PhysicalProperties, Random, Ray, TweenInfo

Enumerations, or enums, are special data types that store (userdata), a set of values specific to that enum. These are read-only values. To access enums in scripts, you need to use a global object called Enum. You can find the list of enums at https://developer.roblox.com/en-us/api-reference/enum.

Here are some examples of how to change other properties that are a data type or enum now. Let’s say you want to create a new part called redBrick with a material of brick and a brick color of red. The part is medium gray stone by default, so to change the color to red, you need to do the following:

redBrick.BrickColor = BrickColor.Red()

Now to change the material of redBrick to brick, get the materials list from enum because Material is an enum:

redBrick.Material = Enum.Material.Brick

Notice as you keep typing the code, the editor autosuggests or autocompletes the code for you.

Conditional Structures

Conditional structures are a way to specify the flow control in programs. If a condition is met, Lua treats it as true; if not, the value is either false or nil. These conditionals can be checked by using the relational operators in Table A.3. For the examples, var 1 is 30 and var 2 is 10.

Table A.3 Relational Operators

Operator

Description

+

Addition, adds two operands; var1+var2 returns 40.

-

Subtraction, subtracts second operand from first; var1–var2 returns 20.

*

Multiplication, multiplies both operands; var1*var2 returns 300.

/

Division, divides numerator by denominator; var1/var2 returns 3.

%

Modulus, gives the remainder after the division; var1%var2 returns 0.

^

Exponent, will give the exponent value; var1^2 returns 900.

Table A.4 shows the conditional operators. For the examples, var1 is 30 and var2 is 10.

TABLE A.4 Conditional Operators

Operator

Description

==

Equal to, (var1 == var2) is not true.

>

Greater than, (var1 > var2) is true.

<

Lesser than, (var1 < var2) is false.

>=

Greater than or equal to, (var1 >= var2) is true.

<=

Lesser than or equal to, (var1 <= var2) is false.

~=

Not equal to, (var1 ~= var2) is true.

Table A.5 shows the logical operators. For the examples, var1 holds the true logic and var2 holds the false logic.

TABLE A.5 Logical Operators

Operator

Description

and

Logical and, if both operands are non-zero then true; (var1 and var2) is false.

or

Logical or, if any two operands are non-zero then true; (var1 or var2) is true.

not

Logical not, reverses the logical state; !(var1) is false.

Expanding Lua Knowledge

If you want to dive deeper into the Lua programming language, the following two excellent resources are readily available on the Web:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.133.96