UOSAGAS Scripting

Aliases & Variables

A serial is an unreadable number like 0x400EED2A. Aliases and variables give those numbers names, so a script can say target 'last' instead of hard-coding something that changes every login.

Built-in aliases

These are always available, with no setup and no declaration. They resolve to a serial the moment they are used.

AliasResolves to
backpack Your backpack.
hand Whatever you are holding.
last Your last target.
lastobject The last item you used.
lefthand The item in your left hand.
righthand The item in your right hand.
self Your own character.
cast 'greater heal'
waitfortarget
target 'self'
 
dclick 'lastobject'     // use whatever you last double-clicked
attack 'last'           // attack your last target

Your own variables

setvar stores a serial under a name of your choosing. With no serial given, the script pauses and asks you to click something.

Ask once, use forever
setvar 'dummy'          // pauses; you click the training dummy
 
cast 'magic arrow'
waitfortarget
target 'dummy'

You can also set one directly, without being asked:

setvar 'homerune' 0x400EED2A

Saved vs script-local

This trips people up, so it is worth being precise:

FormLives whereSurvives a restart?
setvar 'name' Your Razor profile Yes, it is written to the profile
setvar! 'name' The running script only No, it is gone when the script ends

So a target you want to keep (a dummy, a home rune, a pet) uses setvar. A working value you only need inside the loop uses setvar!. That is why the common auto-heal scripts open with:

@setvar! globalTimeout 650   // @ = say nothing, ! = do not save it

Remove a variable with unsetvar, and check for one with varexist:

if not varexist 'dummy'
    setvar 'dummy'
endif

The Variables panel

You don't have to manage variables from inside scripts. The Scripts tab has a Variables sub-tab that lists every saved script variable of your profile: Add prompts for a name and gives you an in-game target cursor, Remove deletes one (with confirmation). A variable created there is immediately usable in any script as !name — and anything a script saves with setvar shows up in the panel.

Capturing with as

as is the third way to get a variable, and usually the best one: it names the result of a search on the spot. See Operators for the full story.

if findtype 3852 self as PotsHeal
    dclick PotsHeal
endif

self, backpack & ground

Three of these names do double duty: besides being aliases, they are valid source arguments for findtype, dclicktype, targettype and counttype.

SourceSearches
backpackYour backpack, including containers inside it.
selfEverything you are wearing and the contents of those containers.
groundItems lying on the ground near you.
a container serialInside that specific container.
if findtype "clean bandage%s%" backpack    // in the pack
if findtype 3852 self                      // anywhere on me
if findtype 0x0EED ground 0 any 3          // gold within 3 tiles

self is wider than backpack: it also covers a pouch on your belt or a quiver. When in doubt for consumables, self is the safer choice.