Since you asked so nicely and also because ai makes writing things much easier than they used to be. My only condition is that once you start making your own missions you have to let me know so I can try them.
Part 1: Getting Started - Your First Mission!
Welcome! This tutorial will guide you through creating your first custom mission. We’ll start with something simple – just printing a message to the console – and gradually build up to a more complex mission.
A Quick Note on Versions: We're focusing on version 2 (v2) of the scripting system, which offers significantly more power than v1. While some concepts from v1 might be familiar, we’ll dive straight into v2 to unlock its full potential.
Step 0: Setting Things Up
Before we begin, you'll need to install the mod itself. There are several guides available in this thread; I'll link to a good one here once someone shares it! (Placeholder for Link).
1. Understanding Threads and Labels – The Building Blocks
Think of missions as being run by "threads." A thread is essentially a sequence of instructions that the game executes, step-by-step. You can have multiple threads running within a mission, but we'll start with just one to keep things manageable.
Labels are like named checkpoints in your script. They mark specific locations where the execution flow can jump to. This allows you to organize your code into logical blocks and control which parts of your mission run when.
2. Creating Your First Thread
Here's the core command that brings it all together:
Code:
mission = CreateThread("testmission")
This line creates a new thread named "testmission." It tells the game, “Hey, I want this to run the code within the label called ‘testmission.’”
3. Defining Your Label – Where the Action Happens
Now, let's define that label:
Important: Notice the colon ( : ) at the end of "testmission." This is
essential! It’s how you tell the game that this line marks a label. Any code indented below the label will be executed when the thread runs.
Indentation and Code Structure
Consistent indentation is absolutely crucial for your script to work correctly. The game uses indentation – typically a single Tab character – to determine which lines of code belong to which labels or control structures (like if statements). Make sure you use a consistent number of spaces or tabs for each level of indentation; mixing them up can lead to unexpected errors!
4. Your First Command: Logging a Message
Let’s add our first command within the testmission: block:
The Log() function displays messages in the game's secondary console window (usually black). This is your best friend when developing missions! Errors and any output from your Log() commands will appear here. It’s highly recommended to run the game in a windowed mode so you can easily see this console, or use a second monitor if possible.
5. Running Your Mission – Let's See It Work!
- Create a Folder: In your <game folder>/CustomMissions2/ directory, create a new folder named super_awesome_mission (or any name you prefer).
- Create the Code File: Inside that folder, create a file named main.code. The filename must end in .code. You might need to adjust your Windows settings to show file extensions and prevent it from accidentally being saved as main.code.txt.
- Paste Your Code: Open main.code in a text editor and paste the following code:
Code:
mission = CreateThread("testmission")
testmission:
Log("I'm alive")
- Save & Launch: Save the file. Start up the game, load a save, and head to your apartment. You should see "I'm alive" appear in the console window!
View attachment 5578655
Congratulations! You’ve just written your first mission! It might not be flashy, but you built it yourself – that's what makes it awesome.
If it doesn't work, look at the console window for any red lines. I'll go over these a little bit in the next post, but there's so many possible causes I'll wait and see what acutally comes up for everyone