Part 2: Reacting to the World - Conditions & Listeners
I. Introduction: Why Conditions and Listeners?
Simply running code isn't enough for a truly interactive mission! Often, we need our missions to
react to what’s happening in the game world – whether it's the player's state, the environment around them, or something else entirely. The core idea is this: "We want our mission to only progress when a certain condition is true."
II. Understanding Conditions:
What are Conditions? Think of conditions as questions we ask the game. They’re like boolean expressions – they evaluate to either true (yes, the condition is met) or false (no, it's not). Essentially, they return a Boolean value.
Condition Types & Syntax:
The full list of possible conditions can be overwhelming, but there's an easy way to explore them! Press F9 in-game and check the BepInEx console window – you’ll find a ton of information about Manaka’s current state. For example, if Manaka is only wearing her coat but it's closed, it might say "Front_Closed" We can use this to trigger events!
Let's imagine we want our mission to react when Manaka opens her coat and give her an orgasm. In our mission, she’s really into exhibiting! We can define conditions using this: CreateCondition("Exposed_Front") will only be true if Manaka's front is fully exposed.
- Curvy Brackets ( ): These are used for "OR" – like CreateCondition("(Exposed_Front, Exposed_Hip)").
- Square Brackets [ ]: These are used for "AND" – like CreateCondition("[Exposed_Front, Exposed_Hip]").
- Exclamation Mark (!): This means “not.” So, CreateCondition("!Exposed_Hip") would be true when Manaka isn't flashing her butt.
You can combine all of these to create really complex conditions! For a full list and more details, remember to check the BepInEx console (Citation 2). You can also compare numbers using operators like >, >=, <, <=, ==, and !=. (Citation 1)
Creating Conditions: We use the CreateCondition() function. For example:
Code:
condition = CreateCondition("Exposed_Front")
This creates a condition that returns true if Manaka has her front exposed.
Performance Tip: It's important to create conditions
before you start using them in listeners – we’ll see why shortly!
III. Introducing Listeners:
What are Listeners? Listeners constantly check a given condition. When that condition becomes true, they trigger an action—in our case, running part of your mission. Think of them as vigilant guards watching for a specific event to happen.
Important Note: Listeners run
once every frame. This means if you put a lot of code inside a listener, it will execute very frequently!
CreateListener() vs. CreateListenerLocal(): There's a subtle difference between these two functions, but for now, just use CreateListenerLocal(). It works well in most simple cases and avoids some potential headaches. Someone more experienced can dive into the details later.
Basic Listener Structure: Here’s a simple example:
Code:
basic_listener:
if condition.Check()
Log("Condition Met")
thread.Goto(next_stage)
The Check() Method: The listener uses the .Check() method to evaluate the condition.
Goto() and Stages: Remember how we talked about threads? We use Goto() to tell the thread where to run next – essentially jumping to a different part of your script labeled with its name.
Variables:
When you write something like condition = CreateCondition(), you're telling the computer to remember the value on the right side of the equals sign in a variable we create on the left. We can then access that value again by using the variable’s name. If this seems confusing, try playing around with something simple:
Code:
name = "Manaka"
Log("Hello " + name)
IV. Combining Conditions & Listeners: A Simple Example
Let's look at a complete example of how to combine conditions and listeners:
Code:
mission = CreateThread("testmission")
testmission:
thread = _this
thread.Goto("start")
start:
condition = CreateCondition("Exposed_Front")
listener = CreateListenerLocal("basic_listener", condition=condition, next_stage="part_1")
part_1:
SetEcstasy(1.1) # Sets the player's ecstasy level to 1 (it's between 0 and 1; half would be 0.5)
# We use 1.1 to make sure Manaka orgasms!
Log("Nice")
basic_listener:
if condition.Check()
Log("Condition Met")
thread.Goto(next_stage)
A Few Notes:
- thread = _this: This is a shortcut to get the current thread, allowing you to control its execution.
- Scope: This can be tricky (and you don't need to understand it right now!), but it allows code in basic_listener to access variables defined in start, even though they’re not technically in the same part of the file. Again, don't worry about this for now – just know that it exists!
- SetEcstasy(): This tells the game to perform an action. The documentation is full of all the things you can call.
V. Best Practices & Troubleshooting:
When things don’t go as planned (and they sometimes will!), the first place you’ll want to look for clues is in the console window. It's your mission control center for debugging!
In this example (which, purely by coincidence, I created to illustrate troubleshooting – totally didn't make any mistakes myself!), the top line tells us exactly what’s wrong: "Inconsistent code indentation in line 6." If we jumped to line 6 in our script and checked, we’d find that I had used spaces instead of tabs—and the game wasn't happy about it! Fixing that simple mistake made the mission work perfectly.
Actually, looking closer, it turns out line 6
was using tabs! The problem was the line above it was using spaces. Sometimes you need to examine the lines around the one the console flags – often, the error is a little more subtle than it initially appears. But generally, the console's pinpointing is pretty accurate.
Pro Tip: You don’t have to quit and restart the entire game every time you make a change! Use
ALT + F9 to reload all your missions—it’s a huge time-saver.
Key Points to Emphasize Throughout Part 2:
- Complexity: Conditions and Listeners are complex topics, but we'll break them down into manageable steps.
- Experimentation: Don’t be afraid to experiment with different conditions and listener configurations – that’s how you learn!
- BepInEx Console: Remember the importance of using Ctrl+F9 and checking the BepInEx console for condition lists and debugging information (Citation 2).