Scripting Basics - Beginner guide to lua and Roblox

Lua (at least this version and predecessors) only has a single number type. double is used for all native numbers.

7 Likes

I call them parameters.

DISCLAIMER: I’m in no position to speak seeing as I haven’t even attempted to make a scripting tutorial (for Lua) before, so just take what I say with a pinch of salt.

Whilst simplification is good and all, over-simplification isn’t the best either.

Personally, if I saw that when I was a beginner programmer (which was way before I even learnt decimals and fractions where a thing), I would assume that it would be limited to integers and would be at a stump whenever I needed decimals.

You missed off a really important part to data types, being booleans. >:(

For variables, mentioning the difference between constants & variables, as well as the _G. variable type (never used this before, makes variable usable across multiple script) could be helpful, as well as that the variable types used in your snippets are all limited to the script that they were initialised in. Local variables also initialise faster, I believe (correct me if I’m wrong, can easily be tested).

The positioning is a bit hectic, I frowned after seeing functions coming up twice - though you could say the same for this post.

If I were to go about an order (this is all me, ya’ll can ignore) for something like this:

  • I’d first address the different data types (strings, integers, booleans etc) and how Lua is different so certain other languages were both integers and floats/doubles/decimal are all treated as numbers.
  • Variables & Constants. Differences, how Lua doesn’t require the type of variable (nor the data type) of a variable to be called along with it. Different types of variables and uses.
  • Functions & Procedures - different use cases etc.
  • The three types of “statements” (maybe more, my programming teacher probably lied to us) - being sequence (i.e. “normal” code), iteration (i.e. loops etc) and selection (i.e. if statements - I call them conditionals). Uses, different types of the different types (i.e. for iteration, while loops, repeat … until loops, etc)
  • Debugging - Good idea to add that

Other stuff :smiley:

Though, good job with the guide…

Nice last paragraph
9 Likes

The first thing I learnt when I was learning to script wasn’t functions, nor variables, nor anything else.

It was learning the correct terminology, specifically the word:

Boolean

(Which took me 3 years to memorise)

And yes, I still have crap memory.

3 Likes

This is just a table set on a global variable, not a variable type. It doesn’t really have a place in a beginner tutorial.

6 Likes

Thank you for all of the feedback! I’ll add some more information on the numbers bit, and add information about booleans (seriously don’t know how I missed those haha). I was planning on getting to statements, I didn’t quite have time last night to formalize those.

However, in terms of other programming languages this is more meant to be a guide to Roblox lua specifically rather than a full on guide to programming. My biggest reason for making this is simply I see a lot of confusion among new scripters. I want to address and explain some of the topics that aren’t always addressed so frequently in tutorials due to their main focus being programming rather than specifically Roblox.

3 Likes

Yes… totally know what that means. Never used it before so no clue how it works, just assumed it was a variable type.

My version of logic dictates (from what you said) that a _G. “variable” is just a global variable that’s added to a table shared between scripts? Correct or incorrect inference?

2 Likes

Wow, what Lua tutorials have you seen? Would love some links or site names because whenever I ever tried to check Lua tutorials, they’d always use Roblox Studio for it (unless it’s the Lua documentation site thing).

2 Likes

Thank you for this great tutorial. This will massively benefit me. Not because I am learning to code, but because I can send a link to this in response to anyone asking me how to learn to code or how I learnt the basics.

3 Likes

You can learn anyway that works for you, everyone is different. I’m simply stating that making it easy to understand is the point of this post. I learned how to use many things in scripting without even knowing what those things were called.

2 Likes

Again this is an entry point topic. The information is correct, just not using the terminology. If I teach someone that the number 10 times the number 10 equals 100, they would know what kids learn both as times tables and multiplication tables. We’re both not wrong, I’m simply stating that you can learn how things work and alternative names and methods that are simpler to understand prior to learning a lot of fancy names and what not. It makes it easier since the target audience of the platform are children.

4 Likes

I more meant focusing on Roblox-specific concepts more than lua-specific. For example there tends to be a lot of confusion specifically related to Roblox events.

Also your reference to _G does seem like something that might go well in this post. _G (in specifically Roblox) simply acts as a table shared among all scripts in the same environment (basically server/client)

_G is actually not even special compared to a table, it’s literally just a shared table which is completely different to vanilla lua.

In vanilla lua, _G represents the global environment of all scripts, so when you use print you’d technically be using _G.print. (That’s actually one reason why lua is used as a missing language, it offers full modification of all functionality including built in lua functionality)

4 Likes

My personal methodology is based on the C#7.2 standard since C# is the main language I use. You may see it fit to go over what Pascal case and camel case are. Usually they are easily portrayed by “PascalCase” and “camelCase” since writing it like that reflects on how the values look.

My sort of “translated standard” for Lua and what I use personally is:

local PrimaryValue = "This value is in the root of the script, so it's PascalCase"
local THIS_VALUE_IS_A_CONSTANT_SO_IT_IS_ALL_CAPS = 0xDEADBEEF

function FunctionNamesArePascalCase(paramatersAreCamelCase)
    local andVariablesInFunctionsAreCamelCaseToo;
end
----------------
local MyModule = {}
-- Lua pseudo-constructor
function MyModule.new()
    local object = {}
    object.PropertiesAndMethodsArePascalCase = true
    return object
end
return MyModule
8 Likes

Very nice tutorial! I am seeing myself in the future using this. Bookmarked too!

(Unrelated but this is my official 2nd post!)

6 Likes

That’s great! :smile: Welcome to the devforum!

5 Likes

I should have some extra content in by this weekend! I have been very busy with school so I haven’t had time to add the stuff I want to :confused:

5 Likes

Okay. Looking forward to it! :smiley:

5 Likes

I’ve searched for how to use for i,x in next() do on the developer hub, how do you use it?

2 Likes

See this page here. It contains the documentation for next.

5 Likes

Actually I’ve updated my post! It now has for loops including next loops and other iterator function loops! :smile: Hopefully this shows you how to use next.

Next is also explained here briefly: Documentation - Roblox Creator Hub

5 Likes

I’m new and u lost me at for loops, could you give more of an explanation, please? Thanks.

1 Like