Basic Scripting Guide

Basic Scripting Guide

This guide covers the fundamentals of creating single-file Lua scripts for PowBot Desktop.

Script Structure

Every script returns a table with lifecycle methods:

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

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

function script:poll()
    -- main loop
    sleep(50)
end

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

return script

Configuration

Use on_config_request(values) / on_config_changed(values) for modern dynamic configuration, then read values from the global options table.

Common controls:

  • select
  • checkbox
  • text
  • number

Common APIs

  • logger for logs
  • players for local player data
  • npcs / game_objects / ground_items for interaction targets
  • inventory / bank for item management
  • movement for walking/pathing
  • stats for UI stats

Example Pattern

Use a simple state machine:

if self.state == "CHECK_INVENTORY" then
    -- ...
elseif self.state == "TASK" then
    -- ...
end

Always include sleep(...) in poll() and nil-check API results before use.

Best Practices

  1. Use clear states.
  2. Sleep in loops.
  3. Check nils before calling methods.
  4. Log important transitions.
  5. Clean up resources in on_stop().