A complete introduction to scripting for games using the versatile Lua programming language and the Core game development platform. Add an array of game coding skills to your toolbox and take your game development to new heights!

Setting Up Your Coding Environment

Setting Up Your Coding Environment

Choosing a good code editor will save you time and heartache. Core actually has a built-in code editor which you can use for this course, but we are recommending you use Visual Studio Code.

Setting up VSCode

To set up VisualStudio to open your Core Lua files:

Install Visual Studio Code

  1. Download Visual Studio Code from the website
  2. Install it by double clicking the downloaded file.

Find the File Path

Next, you will need to find out where the Visual Studio Code program is on your computer.

  • If you have an icon shortcut on your desktop, you can right-click it and select Properties. The Target value is the path to the executable program.
  • If you find it in a search in the Start menu, you can find the path by right-clicking and selecting Open file location…
  • Most recent installs will most likely be at:
    • C:\Users\YourUserNameHere\AppData\Local\Programs\Microsoft VS Code\Code.exe
  • Check out this thread if none of the above suggestions works for you.

Connect Visual Studio Code to Core

  1. Open Core, and from the Create tab, create a new project or open an old one.
  2. Click Edit in the top menu bar, and select Settings…
  3. Paste the file path you found in the previous step into the box by External Script Editor. You can also find it in your File Explorer by clicking the button.

Code Editor Skills

There are several features of a code editor like Visual Studio Code that make it much better than a normal text editor, and are specifically designed to make your coding life easier.

Tab/Untab

Lua uses indentation to separate out blocks of code. You learn more about this in the Conditionals and Functions lessons, but the Tab key is going to be your best friend to indent code.

To un-indent code, moving it back to the left, you can use Shift + Tab. Trust me, you’re going to need this!

Search

In VSCode, you can use Ctrl + F to search your code. This is very useful if you think you switched names or spellings.

Comment/Uncomment

Scripts work by using a specialized vocabulary that the computer understands, and you can’t just write out commands in full sentences and have a program work. However, you can write your own notes in a script using comments, which is a way to use special characters to communicate that the program should not try to understand what you are writing.

In Lua, we use the -- characters to start a comment, and the computer will ignore things you write after them.

-- I can write anything I want! 
-- But usually I write information about what part of the code is supposed to do!

You can also use -- to make the computer temporarily ignore your code, to help figure out which parts are not working.

-- The print function gets Lua to send text back to you
print("This is code I want to run")
-- print("This is code that will be skipped")

In Visual Studio Code, you can use Ctrl + F

Create Your First Script

Create a Script

  1. In your Core project, click the Script button in the top toolbar.
  2. Select Create New Script.
  3. Name your script “HelloLua”.
  4. Press Create Script.

Open the Event Log

To get output from your scripts and to see any errors that they may have, you will need to use the Event Log

  1. In the top menu bar, click View.
  2. Click Event Log to open the Event Log window.
  3. Drag the Event Log tab next to one of the other tabs open in Core, so that you can always see it. I usually put it with Properties and Performance.

Open Your Script

  1. Open the Project Content window.
  2. Find the Scripts section.
  3. Double-click your “HelloLua” script. It should open in Visual Studio Code.

Write the Code

In the script, add your first line of code:

print("Hello, lua!")

Press kbd>Ctrl + S to save your code.

Run the Script

In Core, press the Play button at the top. You should see the text “Hello, lua” appear in the Event Log.

Congratulations! You’re a coder now.

Reading Errors

Coding without bugs would be like a platformer without enemies. We need something to squash!

Errors are unavoidable, and the most important thing for you to know right now is that when your program has an error, the Event Log will tell you the line number of where it occurred.

You will learn about more common errors throughout this course, and have plenty of opportunities to tackle them!

Scroll to Top