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!
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.
To set up VisualStudio to open your Core Lua files:
Next, you will need to find out where the Visual Studio Code program is on your computer.
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.
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!
In VSCode, you can use Ctrl + F to search your code. This is very useful if you think you switched names or spellings.
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
To get output from your scripts and to see any errors that they may have, you will need to use the Event Log
In the script, add your first line of code:
Press kbd>Ctrl + S to save your code.
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.
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!