Learn to Code via Tutorials on Repl.it!

← Back to all posts
Lua - Part 3: Input and Output

Hey, vsauce! Opal here.

What is input?

Essentially, input is just giving information in exchange for output, or an expected outcome! So, if I wanted to make something like a game where I say their name, input will come in. Now, let's try this out!

Now, let me explain what 'io' basically means: it's just input-output. So, an easy way to remember is that we give the code an i, which is input, and it gives us an 'o', which is the output.

What can I even do with this information??

That's a very good and easy question to answer! Let's find out..

Okay, let me explain the dots! I'm basically connecting this variable (which is a string) to the print message. So, what's the output?

Now, this isn't the only use we have for input, as you can even use it for, i don't know, a typewriter, or maybeeee, a calculator! We'll learn how to make a calculator in the next part, so stay tuned. ;)

How can I use this?

Now HERE'S where the fun begins! >:) Let's make a quick character counter......No not video game characters, silly! Lemme show ya:

What does string.len stand for? Well we're asking for a string (which is a type of class), then we're asking for the length of the string! (len). Should make sense.. Anyways, it'll count the characters in the string, and return a value based on the amount of characters there are in the string. Simple and easy!

"This is cool and all..But where's the fun part?"

I'm about to get to that now! I was just teaching what you could use with io.read. Now let's break this up step by step, so you can follow along. I won't give anymore comments, except inside the code blocks ;3




4. Results


I love input, yknow? It's a very interesting and wonderful concept! You can really literally create anything off of input, like a simulator, stock market game, I could go on and on..Ah, input!

I hope you all have a nice november, and staying strong! >:3



Oh nice! We don't see a lot of Lua tutorials here!


@DynamicSquid Haha, yeah! I've been scrolling through the actual lua tutorials out there, and literally none of them help me for a specific thing in learning, so I thought to myself.. "What if I just make them myself?"

And so I did! I've already made 3 parts, and the next part should be either different programming languages (and how they work similar to lua), or just a simple new method in scripting! Most of the tutorials I make are referenced off Roblox Studio.. I'm sure you know what that is by now.. Haha-

But anyways, it's fun making these tutorials, and helping others learn as Iearn too! I'm not even experienced in lua either, I just teach what I know..

And sorry that I'm rambling, it's just that code just excites me! The fact that code runs the very thing that's in my hand, the thing in typing on to you now, my phone, its just incredible!

The fact that a phone can only detect human inputs such as the fingers... Its just, well, exhilarating to know that science and technology gone this far... Its almost scary, actually..

And all these amazing and more excellent programming languages such as LOLCODE, or that could be the name.. Or even "Ruby" because the creator thought python was too complicated,thr very fact we can create a language that a computer can understand with full customisation...?

I could go on and on.. AND THE FACT THAT YOU COULD EVEN PROGRAM A WHOLE VIDEO EDITING SOFTWARE, LIKE DAVINCI RESOLVE?.... man, I just can't believe how far we've gotten in society, to this point. That a simple meme was actually a lot of work behind the scenes.. And it's all thanks to code. The very thing that keeps us alive in general!

.... Oh my, I have rambled quote a lot, haha-.. Sorry if you found it boring, I just carry myself away sometimes hehe-.

Well, I'm glad you liked this tutorial, I put a lot of work into them, and it's nice people appreciate my efforts. I hope everybody has a good day, or night, depends. Anyways, nice coding developers!


Nice, but what does the # represent in #text?


@Baconman321 well, you know the default values for I loops?

for i = 1,5 do....

Well, By using #text I'm counting all the characters in the string, so it'll go through of all of the string in the string.sub command. Hope that helped


@Opalmime Oh, ok

Kind of like the text.length in other languages like JavaScript.

Yep, I got this confirmed: https://stackoverflow.com/questions/17974622/what-does-mean-in-lua


@Baconman321 You can also do


print "Hello World"


@CSharpIsGud This is not what I'm intending, but okay..-