Setting Up Development Environment


description: Learn how to set up your development environment for PowBot Desktop Lua scripting. Get started creating automation scripts with our comprehensive setup guide.

Setting up your development environment

This guide will help you set up your development environment to create Lua scripts for PowBot Desktop.

Step 0 - Pre-requisites

  • Basic knowledge of Lua programming language
  • A text editor or IDE (VS Code, Sublime Text, or any Lua-capable editor)
  • PowBot Desktop client installed and running
  • Understanding of Old School RuneScape game mechanics

Step 1 - Understanding PowBot Desktop Scripts

PowBot Desktop scripts are written in Lua 5.4. Scripts are organized as either:

  • Single-file scripts: Simple scripts with just main.lua and manifest.json
  • Multi-file projects: Complex scripts with modules and utilities

Basic Script Structure

Every script needs a manifest.json file:

{
  "name": "My Script",
  "version": "1.0.0",
  "description": "A simple example script",
  "author": "Your Name",
  "main": "main.lua",
  "min_api_version": "1.0.0"
}

And a main.lua file that returns a script table:

local script = {
    name = "MyScript",
    version = "1.0.0"
}

function script:on_start()
    logger:info("Script started!")
    return true
end

function script:poll()
    -- Your automation logic here
    sleep(50)
end

function script:on_stop()
    logger:info("Script stopped!")
end

return script

Step 2 - Setting Up Your Editor

Visual Studio Code (Recommended)

  1. Install VS Code from code.visualstudio.com
  2. Install the Lua extension by sumneko
  3. Create a .vscode/settings.json file in your script directory:
{
  "Lua.workspace.library": ["~/.powbot/pow_api.d.lua"],
  "Lua.runtime.version": "Lua 5.4"
}

The pow_api.d.lua file in ~/.powbot contains all API type definitions, so the LSP will automatically recognize all PowBot globals without needing to manually list them.

Other Editors

Any text editor that supports Lua syntax highlighting will work:

  • Vim/Neovim with Lua support

Step 3 - Creating Your First Script

  1. Create a new folder for your script (e.g., my-first-script/)
  2. Create manifest.json with the structure shown above
  3. Create main.lua with the basic script structure
  4. Load the script in PowBot Desktop:
    • Hold Ctrl while clicking "Select Script" (or "Load Script")
    • Navigate to your script folder
    • Select the manifest.json file

Step 4 - Understanding the API

PowBot Desktop provides a comprehensive Lua API for interacting with the game:

Common APIs

  • Players: players:local_player(), players:find_all()
  • NPCs: npcs:find_all(), npcs:find_nearest()
  • Inventory: inventory:count(), inventory:find_all()
  • Bank: bank:opened(), bank:open_nearest()
  • Movement: movement:walk_to(), movement:is_moving()
  • Skills: skills:level("Mining")

Important: Use Colon Operator

CRITICAL: Always use the colon (:) operator for API methods:

-- ✓ CORRECT
local player = players:local_player()
local npcs = npcs:find_all({name = "Cow"})

-- ✗ WRONG - Will crash!
local player = players:local_player()
local npcs = npcs:find_all({name = "Cow"})

Step 5 - Testing Your Script

  1. Load the script in PowBot Desktop:
    • Hold Ctrl while clicking "Select Script" (or "Load Script")
    • For multi-file scripts: Navigate to your script folder and select the manifest.json file
    • For single-file scripts: Navigate to and select your single .lua file
  2. Configure any settings if your script has a configuration UI
  3. Start the script and monitor the logs
  4. Debug using logger:info(), logger:warn(), and logger:error()

Example Debugging

function script:poll()
    local player = players:local_player()
    if player then
        logger:info("Player HP: " .. player:hp() .. "/" .. player:max_hp())
    else
        logger:warn("No player found!")
    end
    sleep(50)
end

Step 6 - Best Practices

  1. Always check for nil: Validate API responses before use
  2. Use sleep(): Always include sleep calls to prevent excessive CPU usage
  3. State machines: Organize logic into clear states
  4. Error handling: Handle edge cases and errors gracefully
  5. Logging: Use appropriate log levels for debugging

Next Steps

  • Script Structure Guide - Advanced project organization
  • API Reference - Complete API documentation
  • Filters Guide - Querying game entities

Example Scripts

Check out example scripts in the PowBot Desktop community: