Difference between revisions of "Basic lua: Introduction"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Comments)
Line 10: Line 10:
 
Lua, is similar to programming languages such as C, C#, C++, & Java to name a few, although Lua is relatively basic in comparison. The similarities are based on the structure of the languages & the way that they are written out - ''well for me anyway''.
 
Lua, is similar to programming languages such as C, C#, C++, & Java to name a few, although Lua is relatively basic in comparison. The similarities are based on the structure of the languages & the way that they are written out - ''well for me anyway''.
  
== The basics ==
+
== Why learn Lua ==
=== Print ===
+
Why would you want to learn Lua script? I mean honestly why would you? Visionaire Studio already comes with enough pre-existing actions & queries, that you could technically (almost) make a finished game of commercial caliber; the caliber part being entirely up to you &/or your team, but still...
The print function is used for printing messages to the log file or lua console & is useful for debugging your scripts & functions.
 
<syntaxhighlight>
 
print("hello world") -- prints "hello world" into the log/console (ah yes how cliché of me, but it had to be done)
 
</syntaxhighlight>
 
=== Concatenation ===
 
Concatenation is essentially the joining of two or more strings & is represented by two full stops like so '''..'''
 
<syntaxhighlight>
 
a = "hello"
 
b = "world"
 
  
print(a .. " " .. b) -- prints "hello world" - we had to add " " to create a space between the 2 words
+
My answer is pretty simple. Why not? Lua can be used to further enhance the pre-existing actions & queries, or create entirely new functions & features that do not come standard with Visionaire Studio itself.
</syntaxhighlight>
 
=== Comments ===
 
'''Single line comments''' can be placed on their own line or at the end of a line.
 
<syntaxhighlight>
 
-- this is a single line comment
 
i = 10 -- comment placed after working code
 
-- comment place before code; i = 10 -- notice how the code is also commented out?
 
</syntaxhighlight>
 
'''Multi-line comments''' can be placed anywhere in the script & allow you to write comments over multiple lines.
 
<syntaxhighlight>
 
--[[
 
this is a multiple line comment
 
I can go on & on & on
 
& on & on
 
& on.
 
]]
 
  
local i = 2 * --[[ this is a comment ]] 2
+
Lua is fairly easy to learn, as it has a short learning curve & anyone with any previous programming experience - ''I'm even including basic '''html''' in this category'' - shouldn't have much trouble getting to grips with the basics fairly quickly. Plus you will need to use it, if you want to allow players to create screenshots, or you want to have your game remember the players options configuration each time the game is launched.
print(i) -- would print 4 to the log (2x2)
 
</syntaxhighlight>
 
'''Nested multi-line comments''' allow you to comment out entire blocks of code, even if they already contain multi-line comments, thus preventing existing multi-line comments from ending the nested comment. ''Note: It seems that, nested comments are not included in the geshi lua syntax, as the comments should be completely grayed out, but I can assure that they work''.
 
<syntaxhighlight>
 
--[=[
 
this is a nested comment
 
see how --[[ we can include ]]
 
a multi-line comment inside of it?
 
]=]
 
  
--[[
+
I recommend trying to learn it, even if it's just the basics as from there you can apply what you have learned into other scripting & programming languages & who knows you have an aptitude for learning code & be able to learn more advanced programming languages like c# or c++ & make games in more powerful engines like Unity or UDK (unreal engine).
this is what would happen if we were to use
 
a regular multi-line --[[ comment ]]
 
i = 10
 
]]
 
</syntaxhighlight>
 
 
{{toc}}
 
{{toc}}

Revision as of 14:47, 22 September 2014

What is Lua Script

Lua Script is a lightweight, cross-platform scripting language that was originally created as an extension of sorts, to further extend upon already existing programming languages, but over time, it has grown in popularity due to how easy it is to learn, & the amount of time saved in creating simple procedural scripts, functions & tables, thus Lua script is now the primary or secondary scripting language of multiple game engines. It is also used in various applications & web design.

For more information please see: here & here.

What is the meaning of LUA

Actually it's not LUA at all. Lua is not an abbreviation or acronym of any kind, it is simply the Portuguese word for moon.

What languages is Lua similar to

Lua, is similar to programming languages such as C, C#, C++, & Java to name a few, although Lua is relatively basic in comparison. The similarities are based on the structure of the languages & the way that they are written out - well for me anyway.

Why learn Lua

Why would you want to learn Lua script? I mean honestly why would you? Visionaire Studio already comes with enough pre-existing actions & queries, that you could technically (almost) make a finished game of commercial caliber; the caliber part being entirely up to you &/or your team, but still...

My answer is pretty simple. Why not? Lua can be used to further enhance the pre-existing actions & queries, or create entirely new functions & features that do not come standard with Visionaire Studio itself.

Lua is fairly easy to learn, as it has a short learning curve & anyone with any previous programming experience - I'm even including basic html in this category - shouldn't have much trouble getting to grips with the basics fairly quickly. Plus you will need to use it, if you want to allow players to create screenshots, or you want to have your game remember the players options configuration each time the game is launched.

I recommend trying to learn it, even if it's just the basics as from there you can apply what you have learned into other scripting & programming languages & who knows you have an aptitude for learning code & be able to learn more advanced programming languages like c# or c++ & make games in more powerful engines like Unity or UDK (unreal engine).