Learn to Code via Tutorials on Repl.it!

← Back to all posts
Intresting tutorial (WIP)
elbury (1)

Lua tutorial!!

Yes, we are remaking this in a less understandable way!!!!
NOTE: This may not make sense to you so if you need to read
This is a good and understandable tutorial but mine is like a simplified version of it. anyways happy learning!

Things we will cover in this part

  • basic printing
  • math
  • functions
  • Fun facts
  • difficulty

Basic printing

Printing is one of the first things you will learn when using the Lua language.

First, start by making a new repl use this link if you're lazy.

Ok lets start with this lesson.

Behold the print function.
This function can be used like this
print ("hello world")
and also like this
print ('Hello word')

There also doesn't have to be a space between print and the parentheses
The print function does not have much to it but here's something else you can do with it.
coder100 = 2000
Then you can
print (coder100)
The console will then print 2000.
You can make more variables but I used 1 for this example

Other uses for printing.

Printing can be used in a sort of startup screen, for example
print ("would you like to start the program y/n")
You can and other lines of code to make this actually work.
Printing is a simple function that really can be used for almost anything like taking notes, startup screens, etc.


Comments are little notes that you can put to help remember something or its feedback a comment can be written like this

-- This is a comment.

doing this,
--print ("hello world")
will not type hello world into the console.
This is an example of how you would use a comment.

print ("hi") -- This will print hi to the console.

multi-lined comments

Let us learn how to type multi-line comments
This is how you would write one.

--[[ this

Multi-lined comments are the same as comments, but they are more annoying to type (for me at least). Lua's comments are really not as useful as they can be in other languages.


Variables can be used to assign numbers or specific properties to a word, number, etc. I will give an example.

this = "2"
number = "20"
big = "a"
letter = "pc"

These variables can be used like this.

print (number)

Then the console will print 20. The same goes for the other variables.
let us print a string to go with this.

string = "like this repl"
print = (string)

The console will then show like this repl
Now that we have learned about variables and strings let's dive deeper into strings.


We have learned about strings in the previous section.
this is a string:

string = "poggers"
print (string)

as you know this will put poggers into the console. Strings are like a word version of vairables. Strings can be used to store cheat codes and just overall store info you can also make strings like this:

string = "hey"
string2 = "hi"
string3 = "likes"
Strings can be declared in different ways here's a list:

  • double quotes
  • single quotes
  • double quotes and brackets
    This is where we wrap up our lesson about strings.

if and else

In this section, we will learn how to code if-else statements in Lua.
Statements look like this:

if number == 20
 print ("20 is correct!")
 print ("You guessed incorrectly")

One thing is missing though, We need a variable named number
As you have learned in previous sections we know how to code a variable.

number = "20"

Now that we have the variable we could make the code work.

number = "20"

if number == 20
 print ("20 is correct!")
 print ("You guessed incorrectly")

this is how the code would look like. It may not work but its up to you guys to fix it. Lets try using inputs with if else statements.

io.write("hi can I please get your name?")
name = io.read()
if name = "Enzo"
 print ("Hello Enzo")
 print ("hello stranger")

This can be a startup screen also.
What does this code do you may ask well ill explain.
io.write("hi can I please get your name?") this is where you would type your name it would give you 2 answers 1.) Hello Enzo 2.) hello stranger. After that, name = io.read() is just assigning a name for the response so it's like a variable.

I will cover if then else statements in another part