Skip to content

Running Your First Script

Overview

This page will show you how to write a very simple script skeleton and how to get it to run and show some messages on the console.
Make sure you read the Setting Up Your Development Environment page beforehand. This page will be using the same project made on it.

Script Skeleton

There are a few things you need to have on your class to have DreamBot run your script.

Extending AbstractScript

This will give you access to the onLoop function which you will be using to make the script do the things you want it to do. You can also override other functions but for now we will keep it simple.

import org.dreambot.api.script.AbstractScript;

public class TestScript extends AbstractScript {

    @Override
    public int onLoop() {
        return 0;
    }

}

Adding the script manifest

In addition to extending AbstractScript you will need to add the ScriptManifest so that you can add the script metadata.

import org.dreambot.api.script.AbstractScript;
import org.dreambot.api.script.Category;
import org.dreambot.api.script.ScriptManifest;
import org.dreambot.api.utilities.Logger;

@ScriptManifest(name = "Script Name", description = "My script description!", author = "Developer Name",
                version = 1.0, category = Category.WOODCUTTING, image = "")
public class TestScript extends AbstractScript {

    @Override
    public int onLoop() {
        return 0;
    }

}
Variable Type Description Optional
name String Script name shown in script manager No
description String Description under the script name in the script manager Yes
author String Your DreamBot username Yes
version Double The script version shown in the script manager No
category Category (Enum) Related to the type of work the script will do No
image String The image shown in the script manager Yes

Important

The image variable is the URL suffix of an image uploaded to imgur.com. For example if you have an image with the URL https://i.imgur.com/VVeN1Lv.png you'd need to set it to VVeN1Lv.png.


Writing to console

Now we can write to the console inside our onLoop using the log(String message) method inside the Logger class.

    @Override
    public int onLoop() {
        Logger.log("My first script!");

        return 1000;
    }

The return value is the amount of time the onLoop function will wait until it executes again in milliseconds. So in this case we are going to write to the console every second.

Compiling / Building the artifact

In order to compile the script you just need to build the JAR file (or artifact).
To do this in IntelliJ simply go to Build on top and select Build Artifacts... then just press Build on the next window.

IntelliJ build artifact

If you check the DreamBot Scripts folder you should now have a JAR file belonging to your script.

Starting the script

To run the script simply open the script manager in DreamBot, find your script and start it!
If you have a lot of scripts there you can just select the Local scripts box to have an easier time finding it.

Script Manager first script

If you open the console you should now see the script outputting messages every second.

Script Manager first script