Map Region

Stores a representation of a map region.
Return to Index
new ( integer width , integer height , integer initial_value = 0 )
__gc ( )
__eq ( am.map_region rhs ) -> ( boolean )
size ( ) -> ( integer , integer )
size ( integer width , integer height ) -> ( am.map_region )
data ( integer x , integer y ) -> ( integer )
data ( ) -> ( table )
data ( integer x , integer y , integer value ) -> ( am.map_region )
data ( table values ) -> ( am.map_region )
location ( ) -> ( integer , integer )
location ( integer x , integer y ) -> ( am.map_region )
intersects_with ( am.game_object object ) -> ( boolean )
on ( string event_name , function listener , table content = nil ) -> ( boolean )
off ( string event_name , function listener , table context = nil ) -> ( boolean )
has_event_listener ( string event_name ) -> ( boolean )
new ( integer width , integer height , integer initial_value = 0 )
Creates a new map region instance.
Parameters:
integer width : Width of the region.
integer height : Height of the region.
integer initial_value = 0 : The initial value of each block in the region.
__gc ( )
Releases body part reference counter.
__eq ( am.map_region rhs ) -> ( boolean )
Compares if two body parts are the same object.
Parameters:
am.map_region rhs : The body part to compare with.
Returns:
boolean : True if they are the same object.
size ( ) -> ( integer , integer )
Returns the width and height of the map region.
Returns:
integer : The width of the region.
integer : The height of the region.
size ( integer width , integer height ) -> ( am.map_region )
Sets the width and height of the map region. Existing map region values are maintained if the new size is larger.
Parameters:
integer width : The new width.
integer height : The new height.
Returns:
am.map_region : This.
data ( integer x , integer y ) -> ( integer )
Returns the map region value at the given location.
Parameters:
integer x : The x location.
integer y : The y location.
Returns:
integer : The map region value.
data ( ) -> ( table )
Returns all the map region values in a flat array table.
Returns:
table : All the map region values.
data ( integer x , integer y , integer value ) -> ( am.map_region )
Sets the map region value at the given location.
Parameters:
integer x : The x location.
integer y : The y location.
integer value : The value to set.
Returns:
am.map_region : This.
data ( table values ) -> ( am.map_region )
Sets the map region data from an array table. The given array table does not have to fit into the map region, excess values are ignored. And locations past the end of the given data are left unchanged.
Parameters:
table values : The values to set.
Returns:
am.map_region : This.
location ( ) -> ( integer , integer )
Returns the x and y location of the map region.
Returns:
integer : The x location.
integer : The y location.
location ( integer x , integer y ) -> ( am.map_region )
Sets the x and y location of the map region.
Parameters:
integer x : The x location.
integer y : The y location.
Returns:
am.map_region : This.
intersects_with ( am.game_object object ) -> ( boolean )
Returns true if the given game object intersects with this map region. This will be true if any part of the game object is over a map region value > 0.
Parameters:
am.game_object object : Any game object (am.character, am.item, am.door).
Returns:
boolean : True if it intersects.
on ( string event_name , function listener , table content = nil ) -> ( boolean )
Adds an event listener to this map region.
 local region = am.map_region.new(1, 1, 1)
 region:on("region_entered", function(event)
     am.debug.log("entered: " .. event:game_object)
 end)
 region:on("region_exited", function(event)
     am.debug.log("exited: " .. event:game_object)
 end)
Parameters:
string event_name : The event type or name to trigger on
function listener : The function to call when the event is fired.
table content = nil : An option context for the listener to be called with.
Returns:
boolean : True if the event was added successfully.
off ( string event_name , function listener , table context = nil ) -> ( boolean )
Removes an event listener from the quest. Currently the quest only has events which should only fire once, but if an event listener needs to changed before the event is fire it can be done.
Parameters:
string event_name : The event type the listener was listening for.
function listener : The listener function to remove.
table context = nil : The context which the listener was going to be called with, this is only optional if the listener was added with no context.
Returns:
boolean : True if the event listener was successfully removed.
has_event_listener ( string event_name ) -> ( boolean )
Returns true when there is an event listener for the given event name.
Parameters:
string event_name : The event type to look up.
Returns:
boolean : True if there is any event listener that will be trigged by this event type.