# Big Break

<figure><img src="/files/SU1Q14OdrqhVal5d2Esg" alt=""><figcaption></figcaption></figure>

### Rewards

* :trophy: **350 XP**

**\[Mayor Ishii]** You've heard the news, right? You haven't!? Do you even check your DMs!? We're down a competitor for tonight's RoboBattles! The headline match was supposed to feature Ben Carr, one of our volunteer firefighters. But a wildfire sprung up a few hours ago. His whole squad got called out to fight it. I've been scrambling to find someone to take his place.

I know you haven't been here long, but Zoe tells me you're a total natural. This could be your big break. Do you think you can put a robot together in time? Oh, one very important thing. Tonight's battle is custom controls only.&#x20;

Hurry over to Zoe's Garage and she can help you design your very own control program.

<figure><img src="/files/0sJmSUsJgH8bNS3n5g2j" alt=""><figcaption></figcaption></figure>

**\[Zoe Foxlin]** Ben Carr dropped out? Well yea, I heard that hours ago. I check my DMs.

Make sure your robot has two wheel motors and a weapon motor, like the [Purrmenator](/tutorial/your-first-robot.md). Plug the motors in exactly like this.

<figure><img src="/files/v5PTvjmWTct1fbbUrsWt" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>1</p></figcaption></figure>

We're short on time, so let's start with the control program you wrote for the Martinez Twins.

```python
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
```

We're already using both joysticks, so we'll need to use buttons to control our weapons.

First let's add a line to set up a motor on port C:

```python
# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
motorC = Motor(Port.C)
```

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

Buttons work a little differently than joysticks. Joysticks have a range of motion. We get their position, and then set the motor power to that number, like this.

```python
speedA = controller.joystick_left()[1]
```

Buttons don't have a range of motion. They only have two positions. They're either pressed, or they aren't. So the code for buttons is a little different. We need to check if the button is pressed. Here's some code from one of my old control programs where I used the A button to rotate a motor.

```python
if Button.A in controller.buttons.pressed():
    speed = 100
```

This is called an **`if` statement**. It's basically like a True/False question. If the answer is True, the code inside it will run.

My code checks if button A is pressed. If so, it sets speed to `100` .

Let's add my `if` statement to the area where we set motor speed.

```python
    # Set motor power
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    if Button.A in controller.buttons.pressed():
```

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

When button A is pressed, we should set motor C's speed to `100` . Let's add that line. Give it an extra indent since it's inside the "if statement."

<pre class="language-python"><code class="lang-python">    # Set motor power
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    if<a data-footnote-ref href="#user-content-fn-1"> </a>Button.A in controller.buttons.pressed():
        speedC = 100
</code></pre>

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

Now add a line to rotate `motorC`.

```python
    # Rotate motor
    motorA.dc(speedA * -1)
    motorB.dc(speedB)
    motorC.dc(speedC)
```

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

Your code should look like this.

```python
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
motorC = Motor(Port.C)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    if Button.A in controller.buttons.pressed():
        speedC = 100

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
    motorC.go(speedC)
```

Load it onto our robot and away we go!

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

Um, jk. It's not working. The controller turns off, and the program stops running. Let me ask a chatbot. I'll paste in the full code, and ask:

> why isn't this working?

Hurry up hurry up. We've got a battle to get to. Okay, it says:

> The variable `speedC` is inside an `if` statement, so it's only created if the statement is True.

Oh right! Well there's the problem. We need to make sure the `powerC` variable is created, even if the button isn't pressed. Let's add a line above our `if` statement to create `powerC` no matter what.

<pre class="language-python"><code class="lang-python">    speedC = 0
<strong>    if Button.A in controller.buttons.pressed():
</strong>        speedC = 100
</code></pre>

Now even if the A button isn't pressed, we're still creating `speedC` and assigning a value of `0`.

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

Here's the final code.

```python
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
motorC = Motor(Port.C)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    speedC = 0
    if Button.A in controller.buttons.pressed():
        speedC = 100

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
    motorC.go(speedC)
```

Load it onto your robot and press the A button to rotate your weapon!

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

Almost there. You'll be facing some tough competition in this RoboBattle. You might need your weapon motor to rotate backwards. Especially if your weapon is something like a hammer that raises and lowers, or claw that opens and closes.

Let's use the B button for this. Add two lines to our `if` statement, like this.

```python
    if Button.A in controller.buttons.pressed():
        speedC = 100
    elif Button.B in controller.buttons.pressed():
        speedC = -100
```

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

`elif` is like saying, "if the previous True/False question was **False**, then ask this question."

So if the A button isn't pressed, our code will check if the B button is pressed. If it is, it will set `speedC` to `-100`.

Here's the full program.

```python
# Set up controller
controller = XboxController()

# Set up motor
motorA = Motor(Port.A)
motorB = Motor(Port.B)
motorC = Motor(Port.C)

while True:

    # Set motor speed
    speedA = controller.joystick_left()[1]
    speedB = controller.joystick_right()[1]
    speedC = 0
    if Button.A in controller.buttons.pressed():
        speedC = 100
    elif Button.B in controller.buttons.pressed():
        speedC = -100

    # Rotate motor
    motorA.go(speedA * -1)
    motorB.go(speedB)
    motorC.go(speedC)
```

Take it for a spin!

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

You know what? This is YOUR creation now. The best robot crafters I know all have their own... signature, I guess? The way they control their robots is as unique as their designs. The "right" way to control your robot is whatever feels right to you.

Go ahead and replace `Button.A` and `Button.B` with whatever buttons feel right to you!

* Main Buttons
  * <img src="/files/tLKB7ksyzzBTTPY6QJs2" alt="" data-size="line"> `Button.A`&#x20;
  * <img src="/files/jA6SpkFLbC1YfiEy4Cly" alt="" data-size="line"> `Button.B`&#x20;
  * <img src="/files/F4ztax4sBE5ym9A7CQoC" alt="" data-size="line">`Button.X`&#x20;
  * <img src="/files/ff3ohIMoVa0VE57OsmfB" alt="" data-size="line"> `Button.Y`
* Direction Pad
  * <img src="/files/2Y02NzUZt5fJffWnMpOM" alt="" data-size="line"> `Button.UP`&#x20;
  * <img src="/files/VTJd9v2jHdgIQw3Cyzrf" alt="" data-size="line"> `Button.DOWN`&#x20;
  * <img src="/files/8tc9Eqk68pPmK1jvAxgI" alt="" data-size="line"> `Button.LEFT`&#x20;
  * <img src="/files/6kxDr1UZgd6qTF4uccWI" alt="" data-size="line"> `Button.RIGHT`&#x20;
* Bumpers
  * <img src="/files/J2NHHmao2BfRnM8sb8YY" alt="" data-size="line"> `Button.LB`
  * <img src="/files/iVlckSn0q342TwIKW1TE" alt="" data-size="line"> `Button.RB`
* Face Buttons
  * <img src="/files/4Adz8AtUrCjYzZzLiY2h" alt="" data-size="line"> `Button.VIEW`&#x20;
  * <img src="/files/NGLAC7VlpStOJOvIFpNE" alt="" data-size="line"> `Button.GUIDE`
  * <img src="/files/ixUr1DHCAUyJwUTHvZlm" alt="" data-size="line"> `Button.MENU`
  * <img src="/files/oC99QY226HjvOgDXfbh4" alt="" data-size="line">  `Button.UPLOAD`

Or if you want to use the left and right triggers instead, remove the `if` statements and just set `speedC` with this one line. The trigger positions range from 0 to 100. This line gets the right trigger position and subtract's the left trigger to give the full speed range from `-100` to `100`.

```python
    speedC = controller.triggers()[1] - controller.triggers()[0]
```

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>2</p></figcaption></figure>

With these coding skills and a little math, you can make your robot do literally anything. Combine all movement into one joystick. Use a button to activate a turbo boost. Create an ignition or emergency shutoff button. If you can imagine it, you can code it. Come back another time and I'll help you create some really wild stuff. Today, though... no time to spare. The battle is coming right up.

Give your robot some RoboBattles worthy decorations. Remember, recycling points are the key to victory. Decorations should be wild and whimsical, and they should fall apart easily in battle to earn you the most points. Technic™ pieces are usually hard to break apart, so mostly use bricks! Strong chassis, delicate decorations!

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption></figcaption></figure>

If you have a friend or teammate with another robot, challenge them to battle!

<figure><img src="/files/cr4uiaxfgkU9CKKwdhC2" alt=""><figcaption><p>3</p></figcaption></figure>

[^1]:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://play.robobattles.com/adventure/quests/big-break.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
