A practical guide to the development of LUA Games Learning Note 1

Source: Internet
Author: User

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

    1. Edit the game user interface (the media in which the player interacts with your game)

    2. Define, store, and manage game data (Lua does not have the ability to directly access external databases, but can use C + + components)

    3. Manage game real-time events

    4. Create and maintain a good game storage and onboarding system for Developers

    5. Artificial intelligence (AI) for writing games

    6. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.