of     2   
chevron_rightchevron_rightchevron_right

NotAshley
#185308823Monday, March 14, 2016 6:11 AM GMT

Previous chapter: What is programming? http://forum.roblox.com/Forum/ShowPost.aspx?PostID=185306554 With knowledge of what Lua is, it's time to start learning about how it works. For a minute, think of a Lua script as a movie script. It's read from top to bottom and contains a full detailed explanation about the actions, emotions, and lines for all the actors in the movie. For Lua scripts, it's not much different. It's read from top to bottom by the interpreter (in ROBLOX's case, the game) and is told exactly what to do one step at a time. Since it's a computer acting out this script, every step is completed in a fraction of a second, and the whole thing is usually completed so quickly that it's impossible for us to notice that any time passed at all. Another trait to a computer reading acting out a script is that the lines need to be VERY specific and detailed. If even one instruction has a typo, the computer will get confused, and it won't know how to continue. This is called a syntax error. It sounds confusing, but it will get easier to understand the more we learn. The first step to writing clear Lua instructions is to understand the language that Lua uses to describe certain things. The most important piece of this puzzle is data types. A data type is exactly what it sounds like - a way to represent a type of data. Data is just computer information, such as numbers, words, or other values. To make it less complicated, think of all the different types of information you use on a daily basis in real life. Your age, the time, and the amount of money you have are all numbers, so they can be categorized as the same type of information. Your name, the alphabet, and this tutorial are all made up of miscellaneous letters and symbols, so they can be categorized as the same type of information. Try to think of other examples too! What type of information would your computer's on/off state be? Is it the same type of information as whether or not today is the weekend, or whether or not you're having your favorite meal for dinner? In Lua, the expression of data (which will become more and more important as we progress) is separated into several different types the exact same way. There are more complicated ones, but here is a list of the most basic and commonly used types in Lua: Number - A number! You specify a number in a Lua script by simply typing the number on its own. A number can have math operations performed on it, and can be used to compare other numbers, which is why it's important to be able to specify it. String - Any sequence of characters, e.g. letters, symbols, and even numbers. You specify a string in a Lua script by encasing it in quotes, "like this." Single quotes also work, but you should only use one or the other. The difference between the number data type and numbers inside strings is that the number data type is the only kind treated like a number. If you put a number inside of a string, it will be seen as just text, and you won't be able to use it for math or number comparisons. Strings are most commonly used for displaying messages. Boolean - A boolean value is essentially a switch that only has two possible values: true and false. It also has the most entertaining name out of all the other data types. You can communicate boolean values to Lua by using true and false as keywords on their own, without any quotes or extra symbols (if you encased them in quotes, they would be seen and treated as strings of text). Booleans are commonly used for things that have enabled/disabled or on/off states, e.g. doors and levers, or whether or not a player is dead. Booleans may seem rather useless right now, but comparisons can be made between other data types, and those comparisons can create boolean values that tell you whether or not something is true. In ROBLOX, that helps to allow your game to make choices based on the things that happen in a running server. More on that in another chapter! So now you know how to describe the most basic data types inside of a script. Hang onto this knowledge, because you will need it on every level of Lua, from the basics to the advanced concepts. Almost everything we do in ROBLOX Lua involves manipulating data types to do different things, for example displaying strings as text messages, performing math operations on a player's health to decrease it, or checking booleans to make sure a player is set as an admin before listening to their "/ban all" command. Like I said before, there are more complicated data types, but these are the basic ones that will help you the most often, and these are the ones we will be working with during your introduction to Lua. In the next tutorial, we will load up an actual script in Studio and learn about variables, which allow you to store values using these data types and reference them throughout the script using your own custom-created keywords. Don't get bored, because importance of this will be very clear once we get to the fun parts. I forgot to explain this before, but I plan to keep track of these threads, so if you have questions, post them here and I will try my best to answer them in detail. Thanks for reading!
cntkillme
#185308961Monday, March 14, 2016 6:17 AM GMT

Why isn't nil on the list :( Also "It also has the most entertaining name out of all the other data types" that's really unnecessary lol
NotAshley
#185309001Monday, March 14, 2016 6:19 AM GMT

>Why isn't nil on the list :( I'll get to it! >that's really unnecessary lol Maybe, but it would be boring if everything was presented like an essay c:
LegendaryAccount
#185309028Monday, March 14, 2016 6:20 AM GMT

http://www.lua.org/pil/2.html
NotAshley
#185309059Monday, March 14, 2016 6:21 AM GMT

@Legendary that's useful information, but not formatted very well for beginners who know nothing about programming. My goal here is to describe ROBLOX Lua to somebody who has no background knowledge whatsoever.
lateregistration
#185309539Monday, March 14, 2016 6:41 AM GMT

Lua isn't even a programming language.
Zechariax
#185310313Monday, March 14, 2016 7:17 AM GMT

Lua isn't a programming language, it's a scripting language. The only things you'll be able to do with it are Game scripting, such as Roblox, GMod, and a few other games. It's best to teach people general things every language has so that it is easier to transition between them. If you have a passion for coding, don't waste your time learning ROBLOX Lua. Half the things you learn are only specific to RBLX ( welding scripting, leaderboards, brickcolors, Instance.new, BodyMovers, etc.). Learn something like C++ or Java, or JavaScript if you love website games. But if it is your passion to script for ROBLOX then go ahead. Lua tries to help the bad coders with things like: not needing ;'s, not needing to say the data type of most things, and lack of a true OOP.
Zechariax
#185310392Monday, March 14, 2016 7:20 AM GMT

Also, Roblox was made primarily from C++. So Lua is just making it easier for you to script. C++ is a very powerful language, I highly recommend learning it (as I currently am.) Lua is NOTHING compared to C++. All the Physics, graphics, interfaces, etc. in Roblox are made with C++.
DrHaximus
#185310437Monday, March 14, 2016 7:22 AM GMT

>Lua isn't a programming language, it's a scripting language. "scripting" is the application of the language, it doesn't describe the language itself. Lua and Python are both compiled to a bytecode format and interpreted by the VM. guess what? so does Java! >Learn something like C++ or Java, or JavaScript for what reason? >Lua tries to help the bad coders with things like: not needing ;'s lmao? that's what you find difficult? i think you need to rethink your statements
Thedagz
#185310471Monday, March 14, 2016 7:24 AM GMT

@Drhaximus I absolutely agree :p
Zechariax
#185310554Monday, March 14, 2016 7:28 AM GMT

Java and JavaScript and C++ have more practical uses. If you want to get a job as a developer, Lua is RARELY EVER cared about. Designing apps, games, or websites, you will need one of those 3. Also you might care about Swift for iOS apps or Python for AIs. But Lua, not much. Lua is really simple. The ";" was just an example, stop using 1 example as the basis of your whole argument... Lua is a lot less powerful than C++. Lua is rarely ever used to make a program from scratch. If you want to be a professional programmer, skip over Lua.
DrHaximus
#185310877Monday, March 14, 2016 7:48 AM GMT

so your entire argument is based on "don't bother, it's not directly applicable to my job" you do realize that the concepts of Lua are directly comparable to other languages like Javascript and C++? Lua is simple, concise and unbelievably powerful. it's a great stepping stone to easily understanding other languages.
LuaDeveloped
#185311918Monday, March 14, 2016 9:51 AM GMT

https://en.wikipedia.org/wiki/Category:Scripting_languages weird next to lua it says "(Programming Language)"
Unintelligent_Anon
#185313821Monday, March 14, 2016 12:39 PM GMT

"Lua is a lot less powerful than C++" With all respect intended, why would you make such a direct comparison? It is entirely expected that Lua would be much less "powerful" than C++. It is a "trade/off" of sorts. The low level capabilities are lessened and the ease of usability is proportionately increased. Within certain aspects, versatility is more readily available. Surely you do not believe that the individuals who created Lua were incapable of restructuring it to have said capabilities? Consider memory manipulation, for example. It does not necessarily matter that Lua does not "directly" have the advanced memory manipulation mechanisms readily available(Disregarding "garbage collection") within languages such as C/C++, as Lua was intended for alternative usage purposes. Despite being a "high-level", interpreted language, the vast majority of general programming "concepts" are capable of being implemented. Consequently, it is quite viable in many situations where program "extension" is necessary. If you would like to use "low-level capabilities," consider using a lower-leveled language.
Ezuras
#185314597Monday, March 14, 2016 1:26 PM GMT

Amazing tutorial - keep it up!
MostLikelyNotPaulie
#185315689Monday, March 14, 2016 2:24 PM GMT

"Some games". That's not true. In fact, Lua is very, very common to be used in games. In ROBLOX indeed, Garry's Mod, but also PayDay the Heist and PayDay 2, but also some really, really big ones. Think about STALKER, or Saints Row 2, IV and The Third. Or SimCity. Hey, what about Star Wars Battlefront or Star Wars Empire at War? This list goes on and on, it's huge, I tell you. Don't forget L.A Noire. All I'm saying is, don't tell these people Lua is nothing, because it clearly is. Many games are written in it, or contain it, so it most certainly is a much used, and required scripting language. Lua has way more potential when it comes to games then Java or C++ because it's way more accessible to the game's community. If you look at Space Engineers, which contains C# coding, there is a clearly smaller modding community to that than Garry's Mod, or anything similar. I am going off-topic here, so let me make my final statement. Lua is a fun and easy language, it's flexible and people love it. So don't come on here discouraging people. Also, what the F is this? " Half the things you learn are only specific to RBLX ( welding scripting, leaderboards, brickcolors, Instance.new, BodyMovers, etc.)." Of course they are! Are you blind? "http://roblox.com"! Of course they're going to be specific to ROBLOX. That's with any game. Literally.
Ezuras
#185315724Monday, March 14, 2016 2:26 PM GMT

Lua infact is used universally, but can also be used to make games. Not only that, but its similar to "PHP", which is used for web development.
triode
#185315726Monday, March 14, 2016 2:26 PM GMT

Comparing Lua to C++ is comparing apples and tomatoes. They have some visual details but are completely different. Lua is somewhat a programming language, just leave it at that.
MostLikelyNotPaulie
#185315760Monday, March 14, 2016 2:28 PM GMT

So, rereading your comment, a programming language is only a programming language to you if it is hard? If people can barely get started on something because of the difficulty of something, do you think many people would do it? Of course not. And needing ';'s is kind of stupid anyway. Also, you can use ;'s in Lua so I don't see your problem. system.out.println("Hi!") //errors system.out.println("Hi!"); //doesn't error print("Hi!") --doesn't error print("Hi!") --doesn't error If I saw that, how much effort it takes in Java to stdout something to the output, and how much it takes in Lua and how easy you can do it in Lua, I know what language I'd choose.
MostLikelyNotPaulie
#185315797Monday, March 14, 2016 2:30 PM GMT

Also, Ashleyyyy, please, "before listening to their "/ban all" command.". PLEASE DON'T TURN THIS INTO ADMIN TUTORIAL #930298
TickerOfTime
#185319769Monday, March 14, 2016 4:45 PM GMT

@Zech lol ur a moron
eLunate
#185320630Monday, March 14, 2016 5:10 PM GMT

I'm not saying this is horrible - I think it's great that tutorials are still being attempted, and it looks descriptive. It doesn't feel very comprehensive. I know this is for beginners, even I know from when I learned that if I started here I'd be missing out on fundamental details.
JarodOfOrbiter
#185320691Monday, March 14, 2016 5:11 PM GMT

"It doesn't feel very comprehensive." Says the queen of complicated nomenclature.
eLunate
#185321121Monday, March 14, 2016 5:23 PM GMT

Gxi ne estas komplika se vi povas skribi gxin en Esperanto.
NotAshley
#185342393Monday, March 14, 2016 11:29 PM GMT

@eLunate I plan going into more detail in the next chapters, but from a beginner's viewpoint, what other information do you feel should be included here? Also thanks for making your criticism constructive

    of     2   
chevron_rightchevron_rightchevron_right