backIndex

Xelagot action script

Filters and searching for objects, the Res buffer, (3.1) the Cell buffer

See Surveying, building... and the lists for general information.

Object filters are used to reduce the amount of objects in a collection according to certain criteria. For instance, one may wish to have only objects belonging to a certain citizen, or of a certain model.

This script allows the use of one filter. This filter can be applied to a survey, and the result of filtering can be copied to an object collection called Result, Res for short, and in the Project.

In 3.1 worlds (world server 28 or higher), a Cell buffer is also available, which can be filled with objects of a specific cell. The filter can be applied to this buffer, and the result can be copied to the Res buffer and to the Project.

To prepare the filter, one must first reset it with FilterClear, then one determines the criteria for the search using FilterCitizen, FilterModel etc.

Once the filter is ready, it can be applied in various ways. Copying to the Project is dealt with in the page on Projects, the other two ways are treated here below.

FilterClear clears and resets the object filter
FilterCitizen %c adds citizen number %c to the object filter, turns citizen filtering on. More than one number may be added in successive calls.
FilterModel $m adds model $m to the object filter, turns model filtering on. More than one model may be added in successive calls, or in one string (separated by commas). You may also use wilcards: "street*" will get all street.rwx, street1.rwx etc, "*reet*" will get also treet.rwx...
FilterDescription $d sets description $d to the object filter, turns description filtering on
FilterAction $a sets action $a to the object filter, turns action filtering on
FilterNorthWestHigh @a sets the North, West, High bounds of the object filter, turns on this option. @a may be replaced by any of the location family: &a and ~a
FilterSouthEastLow @a sets the South, East, Low bounds of the object filter, turns on this option. @a may be replaced by any of the location family: &a and ~a
FilterEarlyDate !t sets an early date to the filter: objects created before this date and time are filtered out. !t may be replaced by ~t (object variable) or by a literal (starting with the year) or by a string containing the literal.
FilterLateDate !t sets a late date to the filter: objects created after this date and time are filtered out. !t may be replaced by ~t (object variable) or by a literal (starting with the year) or by a string containing the literal.

Filter and the Res object collection.

ResCount %c Counts the number of objects in the Res collection, and stores that number in %c
ResBounds %n %s %w %e %h %l %c
ResBounds @a @b %c
stores the N, S, W, E, High and Low boundaries of the Res collection (in meters) in variables %n %s %w %e %h %l, or as two location variables @a and @b which represent the oposite vertices of the collection (@a the NW High corner, @b the SE Low corner). Variable %c stores the number of objects in the collection.
ResClear Clears the Res collection, removing all objects from memory.
ResSave $f [%r] saves the contents of the Res collection to file. Optionally %r will contain 0 if the operation succeeds, -1 if it fails.

xelagot 3.607 or newer
The filename convention is explained in the section Filenames. If the destination path and folder does not exist, it will be created to accommodate the file.

xelagot 3.606 or older
The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths.
version 3.07

ResSavePropdump $f [%r]
saves the contents of the Res collection to file in propdump format. Optionally %r will contain 0 if the operation succeeds, -1 if it fails.

xelagot 3.607 or newer
The filename convention is explained in the section Filenames. If the destination path and folder does not exist, it will be created to accommodate the file.

xelagot 3.606 or older
The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths.
ResFromSurvey
ResFromSurveyFilter
loads objects into the Res collection from the Survey buffer. ResFromSurveyFilter applies a filter. Requires a previous Query to have been completed (see Event QueryComplete)
ResFromProjectFilter loads objects into the Res collection from the Project buffer, applying a filter. See also Projects
ProjectFromRes
ProjectFromResFilter
Copies the objects in the Res buffer and adds them to the Project buffer. ProjectFromResFilter applies a filter. Does not clear the buffers. See also Projects
IfGetResObjectItem ~a %i statement1
[Else statement2]
copies an object from the Res collection to object variable ~a, if the object index %i is valid. The index %i must be between 1 and the maximum number of objects (ResCount) in the collection. If successful, executes statement1, otherwise, if an else satement is specified, executes statement2

Filter and the Cell object collection (3.1 world servers). Cell objects can be collected by installing the Event CellContents, and calling GetCellAt @a. After the event is triggered, the following statements can be applied:

CellCount %c Counts the number of objects in the Cell collection, and stores that number in %c
GetCellLocation @a stores the location coordinates of the last cell 'queried' in variable @a.
CellSave $f [%r] saves a the contents of the Cell collection to file $f. Optionally %r will contain 0 if the operation succeeds, -1 if it fails.

xelagot 3.607 or newer
The filename convention is explained in the section Filenames. If the destination path and folder does not exist, it will be created to accommodate the file.

xelagot 3.606 or older
The path defaults to the path of the current script file. A full drive + path may also be specified, see Program paths.
ResFromCell
ResFromCellFilter
loads objects into the Res collection from the Cell buffer. ResFromSurveyFilter applies a filter. Requires a previous GetCellAt @a to have been completed (see Event CellContents)
ProjectFromCell
ProjectFromCellFilter
loads objects into the Project collection from the Cell buffer. ProjectFromCellFilter applies a filter. See also Projects
IfGetCellObjectItem ~a %i statement1
[Else statement2]
copies an object from the Cell collection to object variable ~a, if the object index %i is valid. The index %i must be between 1 and the maximum number of objects (CellCount) in the collection. If successful, executes statement1, otherwise, if an else satement is specified, executes statement2

Example 1.

The bot must find a specific sign object used as a board. This object has a 'create name board' in the action field. Once found, its description must be modified.

#declare your variables for querying
var @QueryPos, %IsQuerying

# declare your variables for the search and modify
var $BoardName, ~Board, %Board
var ~Boarda, $BoardDes

# initialise variables in your code
# the object you look for has in the action field
# 'create name board'
$BoardName = "name board"
# the bot is not yet querying
%IsQuerying = 0

# somewhere in your code, you decide to look for
# your board object at a certain place 
# for instance, where the bot is,
# and change its description
# you must first query the zone
# get the bot's position
GetLocation @QueryPos
# install the event handlers for the query
OnQueryCompleteEvent Complete
OnWorldReconnectEvent Reconnect
# start your query
%IsQuerying = 1
QueryAt @QueryPos
# loop until QueryComplete
Label WaitForQuery
IfInt %IsQuerying = 1 Goto WaitForQuery
# your new description, probably best assigned in a Sub,
# must now be assigned (here just an example)
$BoardDes = "And the winner is XXX !"
# Change the board sign
Gosub MakeBoard
# ~Boarda's object number is automatically updated.
# in this case, because we are dealing with one object
# and not building from within an event handler
# the update is guaranteed to follow the build satement.
# Otherwise, you must install the event handler for ObjectCreate
# and assign the new object to ~Board in the handler and not here
~Board = ~Boarda
# To make sure your object is modified,
# you may install the ObjectResult handler
# (not explained here).
# Once your bot has the object, and has modified it,
# if you are certain no one else will alter the object,
# you may omit the query bit
# next time the bot must alter the object.
# Next time you wish to modify,
# just assign the new description
# $BoardDes = "something here...."
# call Gosub MakeBoard
# followed by ~Board = ~Boarda
#...
End


# in the events and subs section
# for querying

Event Complete
   %IsQuerying = 0
EndEvent

Event Reconnect
   IfInt %IsQuerying = 1 QueryAt @QueryPos
EndEvent

# this Sub finds the first instance of your object
# IfGetResObjectItem ~Board 1

Sub FindBoard
   FilterClear
   ResClear
   FilterAction $BoardName
   ResFromSurveyFilter
   IfGetResObjectItem ~Board 1 %Board = 1
   Else %Board = 0
EndSub

# To modify the description on ~Board and change it to $BoardDes:

Sub MakeBoard
   Gosub FindBoard
   IfInt %Board = 0 Goto MakeBoardError
   ~Boarda = ~Board
   GetDescription ~Boarda $BoardDes
   ObjectModify ~Board ~Boarda
   EndSub
   Label MakeBoardError
   Say Can't find my board :(
EndSub



backIndex