[Unity3d] Unity3d game development Lua with game of bonds (in)

Source: Internet
Author: User

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------

Like my blog Please remember my name: Qin Yuanpei , my blog address is Blog.csdn.net/qinyuanpei.

Reprint please indicate the source, this article Qin Yuanpei . The source of this article: http://blog.csdn.net/qinyuanpei/article/details/39826323

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------

Dear friends, Hello everyone, I am Qin Yuanpei, welcome to pay attention to my blog. My blog address is Blog.csdn.net/qinyuanpei.

If you mention the game development, you will think of C + +, DirectX, OpenGL and other things. But it is well known that the game industry is a rapidly changing industry, if we adopt a compiled language, then we may be very difficult to keep up with the pace of the Times, because the compiled language every time a major update, the entire project needs to be compiled again, this will undoubtedly affect our development efficiency.

So, is there a more efficient game development model? Perhaps the answer has been seen by everyone. The common use in the game world today is to give the underlying logic of the game to the bottom-level language of C + + and give the upper logic of the game to the scripting language.

Because the underlying logic is more efficient and the upper logic is more flexible and convenient to use. For example, the Unreal engine we know is used unrealscripts, which is a language similar to JAVA/C syntax. The Unity3d engine is the c#/javascript/boo of the three scripting languages used, and Cocos2d-x is the lua/javascript of the two scripting languages, which may support many other languages in the future. You may want to ask a question: What is a scripting language? The so-called scripting language is a programming language used to control software applications and only be interpreted or compiled when invoked, which typically stores script code in the form of text. Other words. The scripting language is similar to a directive, which shortens the process of writing a traditional application-compile-link-execute (edit-compile-link-run), which is a program that interprets execution.

Perhaps the moment people invented the scripting language, they never thought of linking scripting language to game development, but scripting language was destined to open up a wider world due to game development. This article will take the current game development in the more popular Lua language as a clue, deep decryption game development field and scripting language inextricably linked.


first, what is LUA?

Lua is a small scripting language. A research group in the Catholic University of Rio de Janeiro, Brazil, was developed in 1993 and designed to embed applications to provide flexible extension and customization capabilities for applications. LUA is written by Standard C. Almost all operating systems and platforms can be compiled, executed. A full LUA interpreter is just 200k, and Lua is the fastest in all of the scripting engines of the moment.

It all determines that Lua is the best choice for embedded scripting. Compared to the kernel of Python and per. Lua's kernel is less than 120KB. The kernel of Python is about 1.1MB 860kb,perl kernel. The LUA language supports object-oriented programming and functional programming, which provides a common type of table tables that enable the functionality of arrays, hash tables, collections, and objects.

LUA supports a synergistic process mechanism.

As an extensible language, LUA provides simple and stable interfaces, such as LUA and C programs that exchange data through a stack, which enables the Lua language to be quickly integrated with other languages. Overall. The LUA language has the following advantages:(1) the language is beautiful, lightweight (2) excellent performance, fast speed (3) strong scalability.

Because of this feature in the Lua language, it is perfectly integrated with the needs of the game development field. Because we need this language, it is able to interact with C + + in a perfect way. Because we need it to encapsulate the underlying. It needs to be simple enough because we need to write code in a simple, flexible, and high-speed way.

Well, obviously Lua is the language we've been looking for.


ii. What can lua do?

Although bloggers have already told us so much about the excellent features of the Lua language, we believe that there are still doubts about the ability of the Lua language. You might think, what can lua do? In the book "Lua game development" the author has already told us the answer:

1. Edit the user interface of the game
2. Define, store and manage basic game data
3. Manage real-time game events
4. Create and maintain developer-friendly game storage and loading systems
5, the artificial intelligence system to write the game
6. Create functional prototypes that can then be ported with high-performance language

At this point we seem to think that the Lua language is, to some extent, born for game development, because it points out a lot of good features to the game development field. So the Lua language into the game development field has become smooth Cheng Zhang, then, let's go down to see it. There are some proven examples of LUA in the game development arena.


third, which games use Lua?

1. World of Warcraft

Assuming that Lua first emerged in the field of games, we cannot help but say "wow". Because of World of Warcraft, Lua was used in its client. The first time that Lua's role in the game field was shown. The Lua language is therefore famous in the field of game development. The LUA-language virtual machine is very lightweight and can be easily embedded into the client program. If you need to update the client, you just need to update the script. No need to compile the entire client again.

This advantage makes LUA a World War One in game development. Being able to say "World of Warcraft" has brought such exciting and great language to the game development field, as Lua tries to gongchenglvede in the field of game, "World of Warcraft" is a must.

2, Big talk West Tour 2

Suppose that "World of Warcraft" to open up Lua in the field of foreign games, then NetEase's "Big Talk of the West 2" is undoubtedly the opening of the domestic game production company using LUA precedent. 2002 when NetEase developed "Big Talk 2", it decided to embed a new scripting language within the client. Because of the use of Microsoft JScript there are many bugs, maintenance inconvenience, poor compatibility. At that time, the project technical director Yunfeng absorbed the "Big Talk West Tour 1" When the overflow of the lesson, decided to choose a new language. This can not only get rid of the reliance on JScript, but also effectively hit the plug makers, weigh repeatedly. Finally, LUA 4.0 was selected. Later, "Big Talk West Tour 2" in the market has been successful, the domestic game development industry has been affected by this impact with LUA, can be said NetEase lua into the field of vision of domestic developers. Just until today. Lua is still a relatively small language in the country. From "Big Talk Tour 2" leads the domestic developer to turn the angle of view to LUA to today nearly more than 10 years time. The reason for this. It's just a matter of thinking to yourself.

3, Gujian Tan

"Gujian Tan" series of games by the Shanghai Candle Dragon Information Technology Co., Ltd. developed a large 3DRPG single-machine game.

The game is set up from "Shan Hai Jing", the story is the martial arts and Xian-man for the creation of themes, the Chinese mythology era as the background, tells the Chinese ancient chivalrous tenderness of the fairy-man culture. "Gujian Tan" series of first-generation and second-generation works with different game engines and different combat modes, although, we can still find a common ground. That is to make LUA the scripting language of the game without exception in the first and second generation works.

For example, the following is an excerpt from the Lua script of the Maple Lake maze scene in "Gujian Tan":

require (" Necessary ") require (" storyutility ") require (" Bigmap ") require (" SCRIPT_DLC4 ")--------------         The following are the initialization functions-------------function Onenterlevel () if getstoryversion () = = 2 then OnDLCEnterLevelM01 () Else If getmainstory () = = 10100 then calltaskfunction ("story10100") ElseIf getmainstory () = = 161900 the N calltaskfunction ("story161900") End If gvalue.mk = = 1 then SHOWNPC ("NPC", FAL             SE) SHOWNPC ("NPC", false) Enabletrigger ("Tri_mk", false) ElseIf gvalue.mk >1 Then SHOWNPC ("NPC", False) SHOWNPC ("NPC", False) SHOWNPC ("NPC", false) SH OWNPC ("NPC", false) Enabletrigger ("Tri_mk", false) Enabletrigger ("Tri_mk", false) end< /pre>
4 , Paladin biography

Since the mention of Gujian Tan, how can not mention the Paladin biography? Although and Gujian Tan Yan generation of works published only a year apart from the "Paladin Five" market response is not as successful as the game maker expected, but the work is commendable place or quite a lot of, because progress is always more than the shortcomings of the well, after all, the times in progress. We can not always take the height of the first generation of the Paladin to ask for a work. Because we are no longer the age of people. And the Paladin will continue to break through themselves, bold innovation and enterprising. Well, we have a temporary first feeling to here, the Paladin four, the Paladin five and the Paladin all use the RenderWare engine. Probably the only difference is the Paladin five and the Paladin all use Lua, the following is a script extracted from the game:

function Baoxiang (id,npcid) player. Control (0) Pid=player. Getmainplayer () player. Setanim (pid,203) Global. Print (ID) Global. Wait (1) y=flag. GetValue (15093)---------thief title obtained-------------Jyd=flag. GetValue (15255) Jyd=jyd+1flag. SetValue (15255,JYD) Global. Print (JYD) Global. AddTimer (0.5,13279)-----------------------------------------if id~=17711 THENNPC. Setanim (npcid,501) Global. Wait (1) End
5 , Jin Yong Group Grand biography Lua re-engraved

    four . take you into the world of Lua
    The last thing I want to share with you is a simple demo of Lua programming, as bloggers think that there will be more and more scenarios for scripting languages in the future. So learning a scripting language can add a lot to the way you develop your game. Because bloggers have just started to learn, so there are shortcomings in the script, I hope you can understand. The time of day in school is decreasing, bloggers hope to spend the last time together with everyone. Bloggers use Lua5.2, which uses the sublime Text2 as a script editor to program with the Luadev plugin. Let's say that you want to use a lazy approach to using LUA for Windows as an integrated environment. OK, here we go, as the first LUA program, we give the code directly, the detailed syntax and API can be consulted on their own.

--while-do Demo sample Code Myval Ue=10while (myvalue <=) doprint (myvalue) myvalue=myvalue+1end--sample table && for-do Demo sample Code mytables={" Item0 "," Item1 "," Item2 "," Item3 "}for i=1,table.maxn (mytables) do print (Mytables[i]) End--complex table Demo sample code mytables= {}mytables["a"]= "ItemA" mytables["B"]= "ItemA" mytables["C"]= "ItemA" mytables["D"]= "ItemA" Print (mytables["a"])--" ItemA "--function Demo sample code function FIB (n) if (n<2) then return n else return fib (n-1) +fib (n-2) endend--math Demo sample code Max Value=math.max (12,23,56,18,10)--56minvalue=math.min (25,34,12,75,8)--8print (maxvalue-minvalue)--48--  String Demo mystring= "Hello This is the cool program language called Lua"; Print (String.find (myString, "Lua"))--48,50--io demo io.write ("Hello I get a powerful program language called Lua \ n") Io.write (String.Format ("This Lua was%s and now is%s \ n", _version,os.date ())) 

The execution results are:



Daily Proverbs: while young. Go the way you want to go. No reason, not to rush.

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcwluexvhbnblaq==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/>


--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------

Like my blog Please remember my name: Qin Yuanpei , my blog address is Blog.csdn.net/qinyuanpei.

Reprint please indicate the source, this article Qin Yuanpei , this article source: http://blog.csdn.net/qinyuanpei/article/details/39826323

--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced. Reprint please specify the author and source, thank you!

[Unity3d] Unity3d game development Lua with game of bonds (in)

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.