Skip to content
Project X

Developer docs

Schedules and the Script Queue

Players can run your script as one part of a schedule: a rotation of scripts on one account, with timed jobs that cut in (for example birdhouse runs every 4 hours). The client's Script Queue runs it, whether the player built the plan in the client or the launcher handed it over in a launch preset. This page covers what the queue does to your script and the few things that make a script behave well in it.

What the queue does to your script

  1. It starts your plugin exactly as the player would by switching it on, with the settings saved in the player's profile. Nothing is passed to your script and nothing new is called.
  2. It stops your plugin by switching it off, so your shutDown() and script.shutdown() run. It does this when the step's time is up, when a goal such as a level is reached, and when a timed job is due.
  3. After a timed job it starts your plugin again on the same plugin instance, wherever the job left the player: often at a bank, sometimes somewhere else entirely. The step keeps the time it had left.
  4. If your script stops by itself, the queue moves on to the next step. It decides whether that was success or failure (next section).

A timed job never stops your script at a bad moment on purpose. It waits until the player is out of combat, out of the Wilderness, not in an instance and not on a boat, and gives up for 15 minutes if no such moment comes. A script can make that decision itself with QueueSafety; see below.

How the queue reads a stop

What happenedHow the queue counts it
Your plugin switched off within 15 seconds of being startedFailed: it didn't start (not owned, missing setting, or it stopped straight away).
It switched off later, and your script's package logged an error (log.error) in the minute beforeFailed: stopped with an error. The step is skipped or retried, as the player chose.
It switched off later with no errorDone: the step ends and the next one starts.

So: use log.error only for real failures, and log.warn or log.info for things the script handled. When your script has finished its job (goal reached, out of supplies it cannot buy), stop it with reliability().stop(reason) as described in Script lifecycle. That reads as “done”, which is what a player with “until it stops” steps wants.

Checklist

Do thisWhy
Start from anywhereAfter a timed job the player may be in a bank in another city. Decide every pass from the game (where am I, what do I carry) and walk to where you work. Never assume the player is already at the spot or holding the right items.
Get your own gearThe queue doesn't load gear for you. If the script needs items, check for them and withdraw them from the bank in the script.
Make shutdown() quick and completeCall super.shutdown() first, then clear every field you keep (state enum, counters, targets) so the next start is clean. Don't block in shutDown(); waits return at once once the thread is interrupted.
Survive a restart on the same instanceYour plugin object is reused. Set start-of-run values (start time, start XP, the state) in run(), not in a constructor or field initialiser.
Never wait for the player at start-upNo dialog that needs a click, no "stand here and press Start". In a schedule nobody is watching. If a setting is missing, stop with a clear reason instead.
Stop when you are doneUse reliability().stop(reason) rather than idling forever, so “until it stops” steps move on.
Mark the moments that aren't safeIf your script has trips (a boss, the Wilderness, a minigame), tell the queue with QueueSafety.

QueueSafety: say when you may be stopped

Without any help, the queue judges a safe moment from the game state, which suits most skilling scripts. A script with trips knows better: the middle of a boss kill can look “out of combat” between hits, and a minigame lobby is not a good place to leave. Tell the queue yourself:

import net.runelite.client.plugins.projectx.bot.QueueSafety;

// leaving the bank for the boss: don't stop me for a timed job now
QueueSafety.setSafeToSwitch(false);

// ...the trip...

// back in the bank between trips: a timed job may cut in here
QueueSafety.setSafeToSwitch(true);
CallEffect
QueueSafety.setSafeToSwitch(false)A due timed job waits, for up to 10 minutes. After that it is put off for 15 minutes, never forced.
QueueSafety.setSafeToSwitch(true)A due timed job may stop your script now, even if the game-state check would have said no.
QueueSafety.clear()Back to the game-state check.
QueueSafety.declared()What you last said: true, false, or null.

The queue forgets what the previous script said before it starts the next one, so you never inherit another script's answer. The calls are cheap, safe from any thread and never wait, so calling them every pass is fine. The best spot is right where your script decides to bank or to leave the bank.

QueueSafety arrived in plugin API 3.3.0 (client 2.40.0). A script that calls it must set minClientVersion = "3.3.0"; an older client would fail to load the class. See Versioning. Scripts that don't call it need no change and keep working in schedules with the game-state check.

Testing your script in a schedule

  1. Build your jar and put it in the dev folder, as usual.
  2. In the client, open Script Queue, add your script for 5 minutes, then another script (or your own again) for 5 minutes, and switch on Loop.
  3. Start it and watch the hand-overs: your script must stop within a few seconds, and start again from wherever the player is.
  4. For timed jobs, make a launch preset in the launcher with Runs: Schedule and a timed job every 30 minutes, then check that your trips are never cut and that your script picks up afterwards.