Intresting tutorial (WIP)
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
- Fun facts
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.
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
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.
--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.
Let us learn how to type multi-line comments
This is how you would write one.
--[[ this is a multi-line comment ]]
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.
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 then print ("20 is correct!") then print ("You guessed incorrectly") end
One thing is missing though, We need a variable named
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 then print ("20 is correct!") else print ("You guessed incorrectly") end
this is how the code would look like. It may not work but its up to you guys to fix it. Lets try using
if else statements.
io.write("hi can I please get your name?") name = io.read() if name = "Enzo" then print ("Hello Enzo") else print ("hello stranger") end
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
I will cover
if then else statements in another part