DEV Community

Kartik Patel
Kartik Patel

Posted on

Zero To Game Dev - First Line Of Code

Introduction

Welcome to Chapter 6 of the Zero To Game Dev course titled First Line Of Code.

In the previous chapter, we explored the Mini Micro environment, learned how the terminal works, and discovered some basic commands that help us navigate the system.

Now it’s time to move one step further.

In this chapter, we will finally write our first MiniScript program.

If this is your first time coding, it might feel a little intimidating at first. That’s completely normal. Every programmer starts exactly the same way.

The good news is that programs don’t begin with complicated systems or large projects. They begin with very small instructions.

One line at a time.

Programming is simply the process of telling a computer what to do, step by step.

In this chapter, we’ll start doing exactly that.

What Is a Program?

Although we already discussed this in Chapter 4, it’s helpful to quickly revisit the idea before we continue.

A program is simply a list of instructions that a computer follows.

Computers don’t think or make decisions on their own. They only perform the instructions we give them, one step at a time.

A good way to understand this is by comparing programs to everyday instructions.

For example:

  • A cooking recipe tells you step by step how to prepare a dish.

  • LEGO instructions show exactly how pieces should be assembled.

  • Directions on a map guide you from one place to another.

Programming works the same way.

A computer receives instructions and follows them in a clear, logical order. This is why programming is often described as step-by-step logic.

Once you understand this idea, programming stops feeling mysterious. It becomes a process of writing instructions that the computer can execute.

If you are completely new to programming, I strongly recommend reading Chapter 4 of this course first, where we explore this concept in much more detail.

Thinking Like A Coder (Before Writing Code)

https://dev.to/kartik_patel/zero-to-game-dev-thinking-like-coder-before-writing-code-1be0

Writing Your First Line of Code

Now it’s finally time to write our first line of code.

We’ll start by typing a simple command directly into the terminal.

If you’ve ever looked at programming tutorials before, you might have noticed that most of them begin with a famous first program called “Hello World.”

For decades, programmers have used it as the first test to confirm that their programming environment is working.

But instead of writing the usual Hello World, let’s make it a little more personal.

For example, my name is Kartik. So I can type this into the terminal:

print "Hello, Kartik"

When you press Enter, Mini Micro immediately prints the message on the screen.


Understanding This Line of Code

Even though this program is only one line long, it already contains three important parts:

  1. print

  2. " " (quotation marks)

  3. Hello, Kartik

Let’s break them down.


The print Function

The word print is something called a function.

A function is simply a predefined instruction that tells the computer to perform a specific task.

Think of it like a small tool that does one job.

For example:

  • a calculator has buttons for different operations

  • a phone has buttons that perform specific actions

In programming, functions work in a similar way.

You call a function, and it performs its job.

The job of the print function is very simple:

It displays information on the screen.

For now, we can think of it as printing text on the terminal.


What Are Quotes?

The quotation marks " " in our code are also important.

They tell the computer that the content inside them is text that should be displayed exactly as written.

Anything inside quotes is treated as a specific type of data.


What Is Data?

In programming, data simply means information that a program can store, process, or display.

Programs work by manipulating different types of data.

For now, we will focus on three basic types:

  1. String

  2. Integer

  3. Boolean

We will explore more data types later in the course.


What Is a String?

A string is a sequence of characters used to represent text.

Examples of strings include:

  • "Hello"

  • "Game Dev"

  • "Hello, Kartik"

In MiniScript, and many other programming languages, anything written inside quotation marks is treated as a string.

This idea is common across many languages such as Python, Go, and GDScript.

So when we write:

print "Hello, Kartik"

We are simply telling the computer:

Print the string "Hello, Kartik" to the screen.


What Happens If We Remove the Quotes?

Now let’s try something slightly different.

Suppose we write this instead:

print X

Mini Micro will show an error.

Why does this happen?

There are two possible reasons.

The first reason is simple: we forgot to put quotation marks around the text.

The correct version would be:

print "X"

But there is another interesting reason that leads us to an important programming concept.


Introducing Variables

If we write:

x = "Hello, Kartik"

print x

The program prints:

Hello, Kartik

Here, x is something called a variable.

A variable acts like a container that stores data.

In this example:

  • x is the variable

  • "Hello, Kartik" is the string stored inside it

When we write print x, the program prints the value stored in the variable.

Variables allow programs to store information and reuse it later, which becomes extremely important when building larger programs and games.

Mounting a Folder

Until now, we’ve been typing small commands directly into the terminal.

But real programs usually grow beyond just a few lines of code. When programs become larger, it’s much easier to store them as script files instead of typing everything again and again.

Scripts allow you to:

  • save your code

  • edit it later

  • run it whenever you want

Before we create our first script, we should connect Mini Micro to a folder on our computer where our programs will be stored.

First, create a new folder somewhere on your computer where you would like to keep all your Mini Micro projects.

Once the folder is ready, go back to Mini Micro and look at the floppy disk icon at the bottom of the screen.

Click the icon and select Unmount User.

You will hear a small sound that confirms the action was successful.

Now click the icon again and choose Mount Folder.

A file selection window will open. Navigate to the folder you created earlier and select it.

After selecting the folder, click Mount.

Your folder is now connected to Mini Micro, and it will be used to store all your scripts and projects.

You have successfully mounted a folder.


Writing a Script File

Now that we have a place to store our programs, we can start writing actual scripts.

While the terminal is useful for testing quick commands, scripts allow us to:

  • write multiple lines of code

  • organize programs more clearly

  • save and reuse our work

Let’s begin by creating a folder for this course project.

Type the following commands in the terminal:

mkdir "Zero-To-Game-Dev"

cd "Zero-To-Game-Dev"

edit

All of these commands were explained in the previous chapter.

If you need a refresher, you can revisit Chapter 5 here:

https://dev.to/kartik_patel/zero-to-game-dev-understanding-mini-micro-k8p

The edit command opens the Mini Micro code editor.


The Editor

You should now see the editor window.

This is where we will write and save our programs.

To save your file for the first time, press:

Ctrl + S

You will be asked to enter a name for the file.

Choose any name you like.

Now let’s write a small program to test everything.

Type the following code in the editor:

x = 45674 + 5678

print x

Once the code is written, press:

Ctrl + R

This shortcut runs the program.

If everything worked correctly, you should see this output:

51352


Why Didn’t We Use Quotes This Time?

Earlier, when we printed text, we used quotation marks.

For example:

print "Hello, Kartik"

But in this example, we didn’t use quotes around the value of x.

That’s because quotation marks are mainly used when working with strings, which represent text.

Here we are working with numbers, so quotes are not needed.

Numbers can be used directly for mathematical operations like addition, subtraction, multiplication, and division.


A Small Experiment

Just for fun, try changing the program.

Replace the code with something like this:

x = 20

print x * 5

Run the program again and see what happens.

Mini Micro will calculate the result and print it.


What Is an Integer?

The numbers we used in the example are called integers.

An integer is a whole number without decimals.

Examples of integers include:

  • 5

  • 42

  • 1000

  • 51352

Integers are commonly used in programs for things like:

  • counting scores

  • tracking health in a game

  • storing positions

  • performing calculations

For now, integers will be the main number type we use while learning programming basics.

Later in the course, we’ll explore other types of numbers as well.

OUTRO

By the end of this chapter, you have written and executed your first MiniScript programs.

You learned how to:

  • mount a folder to store your projects

  • create and save script files

  • run programs inside the editor

  • work with integers and basic calculations

These may seem like small steps, but they form the foundation of everything that comes next.

Every game, tool, or application starts with simple instructions like these.

In the next chapter, we will take the next step and begin working with variables and program logic in more depth. This will allow our programs to store information and behave in more interesting ways.

See you in the next chapter.


Connect With Me

My dev.to account -> https://dev.to/kartik_patel

My Discord server -> https://discord.gg/qStHEDfge7

TEXTUAL

Zero To Game Dev #1 -> https://dev.to/kartik_patel/zero-to-game-dev-1-1n6l

Zero To Game Dev #2 -> https://dev.to/kartik_patel/zero-to-game-dev-what-even-is-game-gii

Zero To Game Dev #3 -> https://dev.to/kartik_patel/zero-to-game-dev-what-is-game-engine-27hh
Zero To Game Dev #4 -> https://dev.to/kartik_patel/zero-to-game-dev-thinking-like-coder-before-writing-code-1be0
Zero To Game Dev #5 -> https://dev.to/kartik_patel/zero-to-game-dev-understanding-mini-micro-k8p

VIDEO

Zero To Game Dev #1 -> https://youtu.be/rbN1BMmSi7s?si=PfguGzXXI2wktCs4

Zero To Game Dev #2 -> https://youtu.be/SOubZShuJCw?si=4uXtHZlLe1Z0-8rM

Zero To Game Dev #3 -> https://youtu.be/ZLz8MM6545I?si=dzO9sAnOxIvmSOX0

Top comments (0)