Scripting in LUA: PART 1 [Printing, Variables, Object-Oriented Programming]

Cheryl Abram
6 min readMay 16, 2022

I’m learning to script in LUA and code in Python. I’m doing LUA first because we (I and my boys) are learning scripting for homeschool and because LUA is similar to Python and it’ll accelerate my leanring once I get more into Python.

We’re learning LUA with the DevKing’s videos which are EXCELLENT! https://www.youtube.com/watch?v=BkYwRdCukZA&list=PLhieaQmOk7nIfMZ1UmvKGPrwuwQVwAvFa

I’ve decided to document my scripting journey b/c I want to share my frustrations and aha moments to (1) look back on this years from now and (2) potentially benefit others just starting out with scripting and coding.

Okay. Let’s get into it.

This post will cover videos 1–4. I write the commentary as I do each tutorial to highlight my ideas as I work through all of this material.

I’m using Roblox Studio for this and it’s getting easier by the day.

Roblox Studio Logo

Tutorial 1: Roblox Studio Basics

The Baseplate starts the server. This is good to know. I need to be sure to enable Explorer, Properties and Output (at a minimum). Yesterday I could not figure out how to see the script at the bottom of the screen, but with these new videos, I figured it out.

I need to be in the Workspace or the ServerScriptService to run script, but I’ll talk more about that later.

I created and renamed my “part” and practiced changing the properties. I got tripped up a little trying to figure out the mechanics between move, scale and rotate, but I got it enough to be comfortable moving on.

Tutorial 2: Printing

The way the DevKing explained printing was very interesting. He said it’s about putting stuff in the output so I can check my code. For example, I printed “Hello World” and nothing happened.

Well, nothing was supposed to happen so that’s okay, but I do like they way he presented the idea of printing.

Keeping notes in my code is amazing and super useful.

Tutorial 3: Variables

Variables are fairly easy to understand but I had to do a few to really get it…kinda. The way I understand it is variable is like my name (Cheryl) and what’s in that variable is my 4 page resume.

Who in the world will spend 20 minutes calling me by my resume (what’s in the variable) when they can spend less than 1 second calling me by my name (the variable)?

Essentially, variables save a thing and give it a name.

I also discovered that in LUA local means it’s on my device and it runs the scripts faster. I’m not sure yet what the other term is when the script is not run on my device.

Tonight I understood that there are no parentheses around the variable.

Below I attempted to add strings (words) vs adding integers (numbers).

BTW, a string is a set of characters (word) the computer can process. Imagine that the string/word is like a sheet on a clothesline and the quotes are clothespins holding the ends.

The quotes/clothespins mark the beginning and end.

Back to what I was saying. Variables don’t need clothespins so, it did not work. Lol!

I also realized I need to pay attention to the variables that I created. I kept forgetting what they were or getting them mixed up.

I finally added that two variables that I defined as integers and it worked.

Tutorial 4: Arithmetic + Object Oriented Programming

So here’s a biggie.

I’ve heard object-oriented for years now and I never really got it. I’m convinced the definitions of object oriented are meant to further confuse us, like the one below.

What the ****! does that even mean?

So it seems that object-oriented simply means a menu with a sub-menu or objects with sub-objects — like those nested dolls!

Essentially, whenever I see dots, this means I’m looking at object-oriented programming or programming with parents and children.

For example, game.workspace.baseplate.

Game is the parent of workspace. Workspace is the parent of baseplate. Baseplate is the parent of something and so on and so forth.

It’s akin to the Linux absolute path.

Or to your family tree where you have a parent, they have parents, they have parents, and so on.

Object-oriented. I get it now.

Below, I used a script to change my Roblox baseplate from plastic to wood!

This is my baseplate before running the script. The baseplate is the gray thing the blue box and roblox character are on.

This is my baseplate after running the script.

My son is going to love seeing how scripts work in real time. I must confess, this is way better than the first way I was learning this material which was just using a book to print scripts without really seeing anything change.

Below I used the variable Baseplate to reduce my need to type alot of words. I also added a note that anything with a checkmark in the properties section means BOOLEAN.

That shined a little more light on my understanding.

I knew that Boolean means either/or (or someting like that) but this just made it stand out even more in my mind. I made the value Anchored, false.

When I ran the script, the false value made my Baseplate disappear b/c it was no longer anchored

BTW, another thing I have to remember is to hit “Stop” to go back to the script. When I don’t do that the “Play” option is greyed out and I’m wondering why.

This is it for tonight. I’ll be back for more commentary as I work my way through learning and practicing LUA.

--

--