Skip to main content

Multi-Client Management

Spawn / remove / iterate clients from a script. Most scripts run with the implicit getClient() parent, but the multi-client globals are useful for orchestration scripts (open the Scripts page, run once, drive every bot).

addClient() -- new bot, random device id
addClient("deviceId") -- new bot, specific device id
addClient("email", "password") -- attach an existing account
removeClient("emailOrDeviceId") -- detach + disconnect
getClient("emailOrDeviceId") -- by identity
getClient() -- the script's parent
getClients() -- all spawned

for i, client in pairs(getClients()) do
-- per-bot work
end

Globals

getClient(key?)

FieldType
Signature(key: string?) → Client?
ReturnsClient?nil when no parent is bound (e.g. global executor with no explicit parent), or the lookup key didn't match a known bot
Common errors"getClient: expected string or nil" (passed something that wasn't a string), "client not found: <key>" (key looked valid but no bot matched)
Asyncyes

Returns the parent client (the bot whose :scripting():execute() ran this script). key is optional — pass an email / bot id / device id to look up a sibling bot.

local me = getClient()
local mate = getClient("[email protected]")

getClients()

FieldType
Signature() → {Client}
Returns{Client} — 1-indexed table of every spawned bot at call time
Asyncyes
for i, client in ipairs(getClients()) do
print(i, client.id, client.username)
end

addClient() / addClient(deviceId) / addClient(email, password)

FieldType
Signature(...) → Client?
ReturnsClient?nil when the manager refused to create the bot (auth failure, capacity, etc.)
Common errors"addClient: expected (), (deviceId), or (email, password)" (bad single-arg shape), "addClient: too many args" (more than 2 args)
Asyncyes

Three call shapes:

CallAuth
addClient()New Android device, random device id
addClient("deviceId")New Android device, specific device id
addClient("email", "password")Attach an existing email/password account
local fresh = addClient() -- random device id
local exact = addClient("PWORLDSANDROID-1234567890ABCD") -- specific device
local acct = addClient("[email protected]", "hunter2") -- existing account

removeClient(emailOrId)

FieldType
Signature(emailOrId: string) → boolean
Returnsbooleantrue when a matching bot was detached + disconnected; false when the key didn't match anything
Asyncyes

Accepts the same identity shapes as getClient(key) (email, bot id, or device id).

removeClient("[email protected]")

Run something across every bot

Pair with runThread for parallel dispatch:

for _, b in ipairs(getClients()) do
runThread(function()
b:warp("MYWORLD")
end)
end