# Lesson 1. Collect resources

[All lessons](tutorials.md) · [Next lesson](tutorial-engage.md)

Build a pilot that drives to a pickup when it has room for that resource and can reach it before it expires. The bot leaves its weapon and toggles idle in this lesson.

## Assemble the tutorial bot

1. In **My bots**, select **Build a bot**.
2. Choose **Mediumweight** and **Relay · Energy** (`medium-energy`).
3. Equip **Pulse Laser**, **Shield Generator**, and **Nanobot Repair System** in that order. Builder displays three mounts numbered 1 to 3. PHP refers to them as slots `0`, `1`, and `2`.
4. Give the bot a name, open **PHP source**, paste the complete script below, and select **Compile**.

Keep this same loadout as you update the pilot in later lessons.

## Write the collection rule

The scan contains the visible pickup, when one is present. Its kind names the resource it restores, and the self snapshot tells you how much of that resource is available. The helper returns early when there is no pickup, the reserve is full, or the estimated trip takes too long. Picking up the resource happens when the chassis reaches it.

```php
<?php
declare(strict_types=1);

function collectPickup(array $scan): bool
{
    $pickup = $scan['pickups'][0] ?? null;
    if ($pickup === null) {
        return false;
    }

    $resources = $pilot->selfState()['resources'];
    $resource = $resources[$pickup['kind']] ?? null;
    if ($resource === null || $resource['current'] >= $resource['max']) {
        return false;
    }

    $x = $pickup['x'];
    $z = $pickup['z'];
    $trip = $pilot->estimateMove($x, $z);
    if ($trip === null || $trip['totalSeconds'] >= $pickup['secondsRemaining']) {
        return false;
    }

    return $pilot->moveTo($x, $z);
}

collectPickup($pilot->scan());
```

The engine runs the script again each tick. The helper can ask the engine for movement again with a fresh observation and a new expiry estimate. Its Boolean return tells you whether movement was queued.

## Reproduce a hull pickup

1. Open **Practice**. Choose **Contested pickups**, seed **20**, **Basic Bot** as **Teammate**, **Field Technician** as **First opponent**, and **Resource Collector** as **Second opponent**. Select **Test run**.
2. Open the decision trace. Until a useful pickup appears, the bot waits. Around 6 simulated seconds a hull pickup spawns. Your bot has taken some hull damage, so it queues a move toward the pickup.
3. Near 7.1 seconds, the replay records the pickup collection. Find the `pickupCollected` event for your bot and check that its hull rose. The pickup restores only the missing amount. In this fixture that is about 7.8 hull.
4. Later, an ammo pickup appears. The bot has a full ammo reserve and issues no move toward it.

Select **Back to bot** and **Save bot** to keep this version. Try seed **21** with the same roster to see a different route to a hull pickup. If a useful pickup remains uncollected in another run, check its `secondsRemaining`, your distance, and the movement outcome. `estimateMove()` assumes a clear path. Another bot can block the route or arrive first.

Continue to [Lesson 2](tutorial-engage.md) or look up unfamiliar terms in the [Glossary](glossary.md).
