Bitfighter  021
The Bitfighter Lua Documentation - Robots, Levelgens, and Plugins
ScriptRunner Class Reference

Main class for holding global methods accessible by all script runners.

Member Functions

addItem(obj)
 Add a BfObject to the game or editor. Any object constructed in a levelgen will not appear in the game world or editor until this method is called on it.
 
findAllObjects(objType,...)
 Returns a table containing a list of objects of the specified type anywhere on the level. [details]
 
findAllObjectsInArea(point1, point2, objType,...)
 Finds all items of the specified type(s) in a given search area. [details]
 
findObjectById(id)
 Returns an object with the given id, or nil if none exists. [details]
 
getGameInfo()
 Returns the GameInfo object. [details]
 
getPlayerCount()
 
pointCanSeePoint(point1, point2)
 Returns true if the two specified points can see one another. [details]
 
subscribe(event)
 Manually subscribe to notifications when the specified event. occurs. [details]
 
unsubscribe(event)
 Manually unsubscribe to the specified Event. [details]
 

Detailed Description

Main class for holding global methods accessible by all script runners.

Script runners include levelgens, robots, and editor plugins. The methods here can be called from all three. However, some may be disabled for a particular script runner.

In a levelgen script, there is an object magically available called 'levelgen' that gives you access to these methods.

Member Function Documentation

◆ addItem(obj)

Arg types: obj: BfObject  |  returns nothing

Add a BfObject to the game or editor. Any object constructed in a levelgen will not appear in the game world or editor until this method is called on it.

Parameters
objAny BfObject to be added to the editor

◆ findAllObjects(objType, ...)

Arg types: objType: ObjType, ...:   |  returns table

Returns a table containing a list of objects of the specified type anywhere on the level.

Can specify multiple object types.

If no object types are provided, this function will return every object on the level (warning, may be slow).

Parameters
objTypeObjTypes specifying what types of objects to find.
Returns
A table with any found objects.
function countObjects(objType, ...) -- Pass one or more object types
objects = bf:findAllObjects(objType, ...) -- Find all objects of specified type(s)
print(#objects) -- Print the number of items found to the console
end
function listZoneIds()
zones = levelgen:findAllObjects(ObjType.GoalZone)
for i = 1, #zones do
id = zones[i]:getId()
print(id)
end
end
Place to deposit flags or get the ball to, depending on game type.
Definition: goalZone__cpp.h:7
table findAllObjects(ObjType objType,...)
Returns a table containing a list of objects of the specified type anywhere on the level.
Definition: LuaScriptRunner__cpp.h:13

◆ findAllObjectsInArea(point1, point2, objType, ...)

Arg types: point1: point, point2: point, objType: ObjType, ...:   |  returns table

Finds all items of the specified type(s) in a given search area.

Multiple object types can be specified. A search rectangle will be constructed from the two points given, with each point positioned at opposite corners.

Note
See findAllObjects() for a code example
Parameters
point1One corner of a search rectangle.
point2Another corner of a search rectangle diagonally opposite to the first.
objTypeThe ObjType to look for. Multiple can be specified.
Returns
A table with any found objects.

◆ findObjectById(id)

Arg types: id: num  |  returns BfObject

Returns an object with the given id, or nil if none exists.

Finds an object with the specified user-assigned id. If there are multiple objects with the same id (shouldn't happen, but could, especially if the passed id is 0), this method will return the first object it finds with the given id. Currently, all objects that have not been explicitly assigned an id have an id of 0.

Note that ids can be assigned in the editor using the ! or # keys.

Parameters
idid to search for.
Returns
The found BfObject, or nil if no objects with the specified id could be found.

◆ getGameInfo()

returns GameInfo

Returns the GameInfo object.

GameInfo can be used to grab information about the currently running game, including the GameType. This only works in-game, not with editor plugins.

Returns
The GameInfo object.

◆ getPlayerCount()

returns num
Returns
Current number of connected players.

◆ pointCanSeePoint(point1, point2)

Arg types: point1: point, point2: point  |  returns bool

Returns true if the two specified points can see one another.

Parameters
point1First point.
point2Second point.
Returns
true if objects have a line of sight from one to the other, false otherwise.

◆ subscribe(event)

Arg types: event: Event  |  returns nothing

Manually subscribe to notifications when the specified event. occurs.

Parameters
eventThe Event to subscribe to.
See also
The Event page for a list of events and their callback signatures.

Note that this method is equivalent to the subscribe method on bots and levelgens.

◆ unsubscribe(event)

Arg types: event: Event  |  returns nothing

Manually unsubscribe to the specified Event.

Note that this method is equivalent to the unsubscribe method on bots and levelgens.