This article only makes personal study notes!
the advantages of the LUA scripting language : Free, compact, fast, and portable.
Lua in the game project, you can do the following work
Edit the game user interface (the media in which the player interacts with your game)
Define, store, and manage game data (Lua does not have the ability to directly access external databases, but can use C + + components)
Manage game real-time events
Create and maintain a good game storage and onboarding system for Developers
Artificial intelligence (AI) for writing games
Create functional prototypes that can then be ported with high-performance languages
Getting Started with Lua
LUA Console
Lua script (text text with. Lua extension)
code block (Chunk): A single command or a series of commands that make up a script file
Dofile: Used to execute scripts immediately
"\ \" instead of a single slash, a single slash is used to tell Lua to run the environment behind him special symbols
LUA Basics
1 Advantage: can integrate C + + module to extend its function
2 Language definitions: You cannot use numbers as a starting character, and you should avoid underlining (_) uppercase letters
3lua Reserved Keywords:
and
|
Local
|
Break
|
Nil
|
Do
|
Not
|
Else
|
Or
|
ElseIf
|
Repeat
|
End
|
Return
|
False
|
Then
|
For
|
True
|
function
|
Until
|
If
|
While
|
Inch
|
|
|
|
4 variables: Variables do not need to be declared before use, the type depends on the value assigned to it by the user.
5 Types of variables: nil, Boolean, string, number, and table
Nil: Used to indicate that the variable has not been assigned a value. Example: myvalue = Nil
Boolean: There are only two kinds of true and false variables. Example: MyValue = True
String (String): In Lua, strings can be as small as one character, or can contain more than million characters
Number (double-precision floating-point number)
Table (data type)
5 Local variables and global variables
The default is global
The valid range of variables depends on the location of the declared variable, for example:
function Myfun ()
Local MYX = 7
If Myx < ten Then
Local MyY = "Hello World"
Print (MyY)
End
Print (MyY)
End
Execution Result:
Hello World
Nil
Operator (special symbol): Can make two worth of calculation results
Arithmetic operators:+-*/(a+b=c)
Relational operators:= =,~=,<,>,<=,>=(if (a = = b) Special: Table, Only two table is the same object to get the expected result)
Logical operators: And, OR, not
and
|
When comparing two parameters, returns False if the first is false otherwise returns the second value of the argument
|
Or
|
Contrary to and
|
Not
|
Returns true and False,false and nil are treated as false, others are true
|
6 Control structure
All control structures are ended with end tags
if: True, the block will be executed, for example:
function Myfun ()
A = 7
If A<10 Then
Print ("<10")
End
If A>5 Then
Print (">5")
End
End
Results:
<10
>5
while and repeat: You can cycle through a script (while first judging, repeat after the decision (to ensure that the program executes at least once))
for: Allows a user to execute a script in a limited number of times based on the value of an expression
For index=1,10 do
Print (index)
End
For the range of variable values to be provided, the block is executed at the same time that each value of the range is traversed, and end ends
Break: You can force exit from the loop control structure
Let's summarize here today ...
Lua Game Development Practice Guide Learning Note 1