Programming Concepts - Introduction and Code Processing

you know what, programming tutorial series directly on the devforum.

Last Chapter (N/A) | Next Chapter (Variables and Data Types) [TODO]

Motivation

I wanted to make a full guide to how to program on Roblox because the tutorials I’ve found leave a lot of problems.

The biggest problem with a lot of tutorials is that they don’t teach you actual programming concepts, they teach you the Roblox API, and treat concepts as the second class. That’s why, for these tutorials, I want to teach you conceptual programming and leave Roblox and Lua out of it, I’ll bring them in when it’s relevant, usually at the end of the chapter, but you’ll learn more skills if you don’t couple yourself to a single language or domain.

I also don’t want to focus on language syntax directly, as, in my opinion, you’ll pick this up naturally as you learn the concepts in this guide. This thread already shows how to call the print function with a string (dont worry!! i’ll explain these in the next chapter!).

This foreword wont be present in future threads. Its here for the first part so you know my intentions with this project.

I want your feedback

If anything isn’t explained that well, feel free to leave a reply on this thread. I’ll only respond to questions that correlate directly to this thread’s content.

1. Code Processing

For this first thread, I’m going to teach how computers process code. There’s no point diving into language concepts, without knowing how computers process code in the first place.

Take an instruction list, I would assume these are pretty obvious in their form. Lets use the example of making a ham and cheese sandwich. How would you go about this?

assuming you have the ingredients lol

Well first, you’d want to get bread, cheese and ham. Lets write this down in our instruction list.

  1. Get two slices of bread
  2. Get a block of cheese
  3. Get some ham slices

I’m not combining instructions, you’ll figure out soon when I tie this back to code

Notice how the instructions are numbered, what you’re doing is reading the top line, then going to the next one and so on. This is what a computer does, but in a more code-like form. It first gets the slices of bread, then gets a block of cheese, and finally some ham slices. To better represent this, lets take a simple pseudocode script.

Pseudocode is a way of representing code-like statements in a higher level form, they dont represent real code, but its useful for drafting down what you want code to do before writing it out in the actual target language.

Get 2 slices of bread
Get a block of cheese
Get a slice of ham

We can then translate this to Lua which, hey presto, we have some code that the computer can process

print("obtained 2 slices of bread")
print("obtained a block of cheese")
print("obtained a slice of ham")

If you put this in a Script in the workspace, run, then observe the output. You’ll notice that the order that these mystical print objects are processed is from the top, to the bottom.

How do I open the Output view

With the new ribbon, it’s under the Script tab.

On the old UI, it’s under View

image

If you haven’t opened it before, it should appear at the bottom of Studio


We’ll explain what print() does and what "text" is all about in the next chapter I make.

Closing Statement

For this chapter, I only wanted to explain the bare bone fundamentals of code processing, for the next, I’ll start going into data types and variables, as these are two very useful concepts to nail down early on, and what that mythical print text does. (You can probably make some educated guesses, if you ran the script).

Please don’t solely rely on my tutorials though, I want you to try some stuff with what I’ve taught with these guides, for this specific chapter, its not that relevant since I haven’t introduced any concepts, but you could still experiment with print() and " " before I make the chapter on Data Types.

Challenges

When I do start introducing concepts, I’ll leave a little challenge here so you can better learn concepts introduced, for this one, I’m actually going to give you a little challenge that involves the content of the next chapter. Use something to generate a random number, and print it to the output.

The solution will be at the end of the next chapter.

When you do solve it, please spoiler the solution using detail dividers.

6 Likes

Here’s the planned chapters, since I have this planned out.

  1. Introduction and Code Processing (this one)
  2. Data Types and Variables (what x = value does, and common data types in languages)
  3. Conditions and Branching (how to use if to control what code runs based on conditions)
  4. Math (how to do math in programming, wont go into math from Lua’s library)
  5. Conditional Loops (looping, repeating the same code, when a condition is true)
  6. Arrays and Dictionaries (what { } is used for)
  7. Iterative Loops (looping between two numeric values, or in a collection)
  8. Functions (how to create code chunks that you can reuse in multiple places)
  9. some more stuff?

I’m going into this assuming you’ve never read a code file before. The code reads from top-to-bottom thing isn’t as commonplace knowledge as you think it is. This is primarily an introduction explaining my motivations behind it, the code flow thing is there mostly to teach a concept in the tutorial.

The motivation section only appears in this chapter, and subsequent chapters will be almost completely concept based (with a bit of Lua to nail it home).

1 Like