Editing Lua

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
'''Lua''' is the scripting language used by [[MegaGlest]] for all scripted [[scenarios]] and tutorials. It allows dialogue with the player, and allows you control over the enemy, such as to make a scenario where you must destroy the enemy villages in order, or something were you must survive a special enemy attack with different starting [[units]]. It can be made so you can have missions where your goal is to protect a certain unit, such as a [[summoner]] or an allies [[castle]]. You have full control over what the foe does, and this is very handy for making a unique scenario. All tutorials are scripted. They are simply easy scenarios that teach you as they go.
+
'''Lua''' is the scripting language used by [[Glest]] for all scripted scenarios and tutorials. It allows dialogue with the player, and allows you control over the enemy, such as to make a scenario where you must destroy the enemy villages in order, or something were you must survive a special enemy attack with different starting units. It can be made so you can have missions where your goal is to protect a certain unit, such as a summoner or an allies castle. You have full control over what the foe does, and this is very handy for making a unique scenario. All tutorials are scripted. They are simply easy scenarios that teach you as they go.
  
 
==Basics==
 
==Basics==
The best part about lua is that the lua used in MegaGlest is very easy to learn, only a bit harder than the XMLs, and easier than learning to model. lua script is placed in between the scripts tag of the scenario XML, and should have an included .lng file in the same directory if dialogue is used (more on this later).
+
The best part about lua is that the lua used in Glest is very easy to learn, only a bit harder than the XMLs, and easier than learning to model. lua script is placed in between the scripts tag of the scenario XML, and should have an included .lng file in the same directory if dialogue is used (more on this later).
  
Lua is a straight forward language in MegaGlest, existing simply of [[MG/Lua|commands]], many which check to see if event A has occured, then event B can start.
+
Lua is a straight forward language in Glest, existing simply of commands, many which check to see if event A has occured, then event B can start.
  
The basics of lua are simple. In MegaGlest, a command does a certain function to a certain unit, faction, team, or the screen. Comments can be placed with --, where everything after the -- is commented out until the end of the line. The most important thing to remember is that the faction numbers are 0, 1, 2, and 3. NOT 1, 2, 3, 4. Player 1 is known as player 0 here. This is called the faction index, and is used in many functions that affect a faction/player. Lastly, remember that lua is case sensitive. createUnit is not the same as CreateUnit.
+
The basics of lua are simple. In Glest, a command does a certain function to a certain unit, faction, team, or the screen. Comments can be placed with --, where everything after the -- is commented out until the end of the line. The most important thing to remember is that the faction numbers are 0, 1, 2, and 3. NOT 1, 2, 3, 4. Player 1 is known as player 0 here. This is called the faction index, and is used in many functions that affect a faction/player. Lastly, remember that lua is case sensitive. createUnit is not the same as CreateUnit.
  
 
==Unit IDs==
 
==Unit IDs==
First of all, an important concept to understand is that all units in MegaGlest have a unique number assigned to them, and lua needs to use this number to control the units. However, you don't have to directly know the numbers, and you'll never use the number itself. We will always use variables and functions to get these unit IDs. The best way to get a unit ID is right after we create the unit (with createUnit()) by using the command lastCreatedUnit(), which gives the unit ID of the last created unit.
+
First of all, an important concept to understand is that all units in glest have a unique number assigned to them, and lua needs to use this number to control the units. However, you don't have to directly know the numbers, and you'll never use the number itself. We will always use variables and functions to get these unit IDs. The best way to get a unit ID is right after we create the unit (with createUnit()) by using the command lastCreatedUnit(), which gives the unit ID of the last created unit.
  
 
So if we use a variable, such as myVar (variables in lua are loosely typed and do not need to be declared in any way), we can say myVar=lastCreatedUnit(), so now the unit ID of the last created unit is stored in 'myVar'. Note that we can only get the unit ID of a unit when we create them, so we cannot get IDs of units later.
 
So if we use a variable, such as myVar (variables in lua are loosely typed and do not need to be declared in any way), we can say myVar=lastCreatedUnit(), so now the unit ID of the last created unit is stored in 'myVar'. Note that we can only get the unit ID of a unit when we create them, so we cannot get IDs of units later.
Line 42: Line 42:
  
 
==List of Lua Commands==
 
==List of Lua Commands==
For Lua commands shared by all engines, including regular Glest, please see [[Lua/Commands]]. For [[MegaGlest]], see [[MG/Lua]]. For GAE, see [[GAE/Lua]].
+
For Lua commands shared by all engines, including regular Glest, please see [[Lua/Commands]]. For [[MegaGlest]], see [[MG/Scripted Scenarios]]. For GAE, see [[GAE/Lua]].
  
 
==External Links==
 
==External Links==
Line 50: Line 50:
 
*[http://lua-users.org/wiki Lua-Users.org Wiki]
 
*[http://lua-users.org/wiki Lua-Users.org Wiki]
 
[[Category:Scenarios]]
 
[[Category:Scenarios]]
[[Category:Lua]]
 
[[Category:XMLs]]
 

Please note that all contributions to MegaGlest are considered to be released under the Creative Commons Attribution Share Alike (see MegaGlest:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)