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.luaandmanifest.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)
- Install VS Code from code.visualstudio.com
- Install the Lua extension by sumneko
- Create a
.vscode/settings.jsonfile 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
- Create a new folder for your script (e.g.,
my-first-script/) - Create
manifest.jsonwith the structure shown above - Create
main.luawith the basic script structure - Load the script in PowBot Desktop:
- Hold Ctrl while clicking "Select Script" (or "Load Script")
- Navigate to your script folder
- Select the
manifest.jsonfile
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
- 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.jsonfile - For single-file scripts: Navigate to and select your single
.luafile
- Configure any settings if your script has a configuration UI
- Start the script and monitor the logs
- Debug using
logger:info(),logger:warn(), andlogger: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
- Always check for nil: Validate API responses before use
- Use sleep(): Always include sleep calls to prevent excessive CPU usage
- State machines: Organize logic into clear states
- Error handling: Handle edge cases and errors gracefully
- 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:
- PowBot Discord - Community scripts and examples
- PowBot Store - Browse available scripts