Show
Analyticsvoid function Analytics.log(category, action, label) ["hide"]
Show
Arrayvoid function Array:new(arr)
void function Array.normalize(arr)
void function Array:forEach(callbackFunction) @type Array Iterates over all elements of the array and applieds a function on them. This is especially useful to avoid explicit use of a for loop. However, this functional style comes at an allocation and performance cost because of the function. Use it when it suits your needs.
array function Array:map(mapFunction) Maps all elements to a new array using a given function.
array function Array:filter(filterFunction) Creates a copy that only contains filtered elements.
number function Array:count(predicate) Counts how many elements fulfill a given predicate. for an element of the array.
bool function Array:exists(predicate) Returns true if at least one element matches the given predicate. for an element of the array.
numbers function Array:add(element, index) Adds an object to the array. An index can be provided to specify a position for insertion. If no index was provided the object will be appended to the array.
numbers function Array:addAll(arr, index) Adds an object to the array. An index can be provided to specify a position for insertion. If no index was provided the elements will be appended to the array.
number function Array:find(element) Returns the index of an object in the array. If the array doesn't contain it the function returns -1.
bool function Array:contains(element) Returns true if the given object is part of the array.
bool function Array:isEmpty([]) Returns true if the array is empty. This is equivalent to checking the size size of the array being 0 manually.
void function Array:removeAt(i) Removes the object at a specific index.
bool function Array:remove(element) Removes the first appearance of an object from the array.
void function Array:clear([]) Clears the array by removing all elements. The resulting size of the array will be 0.
void function Array:sort(compFunc) Uses natural order of the elements in the array to sort them. You can optionally provide your own function for comparing two elements. specifying whether the first argument should be before the second argument in the array. The default behaviour is ascending order.
void function Array:shuffle([]) Shuffles the elements of the array into a random order. The function uses _math.random_ internally so that the result is dependent on the current random seed value. To get diferent results for diferent runs you might call >_math.randomseed(os.time())_ at the start of your program.
void function Array:pick([]) Returns a random element of the array. Returns **nil** if the array is empty.
array function Array:sub(startIndex, length) Creates a sub-array for the specified range. will be copied to the end.
array function Array:copy([]) Returns a copy of the array.
string function Array:join(separator) Joins the contents of the array into a string using the specified separator.
void function mt:__tostring([])
void function Array.fromJavaList(list)
void function Array.fromJavaArray(arr)
void function Array.normalize(arr)
void function Array:forEach(callbackFunction) @type Array Iterates over all elements of the array and applieds a function on them. This is especially useful to avoid explicit use of a for loop. However, this functional style comes at an allocation and performance cost because of the function. Use it when it suits your needs.
Code: Select all
local a = Array{1, 2, 3}
for i = 1, #a do --Typical approach
print(a[i])
end
a:forEach(function(x) print(x) end) --Functional style
Code: Select all
local a = Array{1, 2, 3}
local b = a:map(function(x) return 2 * x end)
print(tostring(b)) --Prints {2, 4, 6}
Code: Select all
local a = Array{1, 2, 3}
local b = a:filter(function(x) return x % 2 == 1 end) --Keep uneven numbers
print(tostring(b)) --Prints {1, 3}
bool function Array:exists(predicate) Returns true if at least one element matches the given predicate. for an element of the array.
numbers function Array:add(element, index) Adds an object to the array. An index can be provided to specify a position for insertion. If no index was provided the object will be appended to the array.
Code: Select all
local a = Array()
a:add(1)
a:add(2)
a:add(3, 1)
print(tostring(a)) --Prints {3, 1, 2}
Code: Select all
local a = Array{1, 2, 3}
local b = Array{4, 5, 6}
a:addAll(b, 2)
print(tostring(a)) --Prints {1, 4, 5, 6, 2, 3}
Code: Select all
local a = Array{'a', 'b', 'c'}
print(a:find('b')) --Prints 2
Code: Select all
local a = Array{'a', 'b', 'c'}
print(a:contains('b')) --Prints true
print(a:contains('d')) --Prints false
Code: Select all
local a = Array()
print(a:isEmpty())
a:add(1)
print(a:isEmpty())
bool function Array:remove(element) Removes the first appearance of an object from the array.
void function Array:clear([]) Clears the array by removing all elements. The resulting size of the array will be 0.
void function Array:sort(compFunc) Uses natural order of the elements in the array to sort them. You can optionally provide your own function for comparing two elements. specifying whether the first argument should be before the second argument in the array. The default behaviour is ascending order.
Code: Select all
local arr = Array{1, 5, 0, 6, 1, 3, 2, 4}
arr:sort()
print(tostring(arr)) --Prints {0, 1, 1, 2, 3, 4, 5, 6}
arr:sort(function(a,b) return a > b end)
print(tostring(arr)) --Prints {6, 5, 4, 3, 2, 1, 1, 0}
Code: Select all
local a = Array{0, 1, 2, 3, 4, 5, 6}
a:shuffle()
print(tostring(a)) --Prints {5, 3, 4, 1, 6, 2, 0}
Code: Select all
local a = Array{1, 2, 3}
print(a:pick())
Code: Select all
local a = Array{1, 2, 3, 4, 5, 6}
print(tostring(a)) --Prints {1, 2, 3, 4, 5, 6}
local b = a:sub(2, 4)
print(tostring(b)) --Prints {2, 3, 4, 5}
Code: Select all
local a = Array{1, 2, 3}
local b = a:copy()
b[1] = 42
print(tostring(a)) --Prints {1, 2, 3}
print(tostring(b)) --Prints {42, 2, 3}
void function mt:__tostring([])
void function Array.fromJavaList(list)
void function Array.fromJavaArray(arr)
Show
Builderbool function Builder.isBuildingBuildable( draft, x, y) Checks whether the specified building draft can be built at the given position x, y. Returns true if the building can be built.
number function Builder.getBuildingPrice( draft, x, y) Returns the price of the building. May change with time.
bool function Builder.buildBuilding( draft, x, y, frame) Tries to build the given building draft at the specified position and sets it's frame if a frame was specified. Returns true if the build was was successful. was specified a random frame will be used (in case the building has multiple frames).
void function Builder.getBuildingUpgradePrice(draft, x, y)
void function Builder.buildBuildingUpgrade(draft, x, y)
void function Builder.removeBuildingUpgrade(draft, x, y)
bool function Builder.isRoadBuildable(draft draft, x0, y0, x1, y1, level0, level1, bridge) Checks whether the specified road draft can be build along the given line x0,y0 - x1,y1. To build a bridge manually you have to set level0 = level1 and bridge = true Only a single lane will be built so a valid line has to fulfill the property x0 == x1 or y0 == y1 For this option to work _level0_ and _level1_ must be equal. Default is **false**.
number function Builder.getRoadPrice( draft, x0, y0, x1, y1, level0, level1, bridge) Returns the price of the road. May change with time. For this option to work _level0_ and _level1_ must be equal. Default is **false**.
bool function Builder.buildRoad(draft draft, x0, y0, x1, y1, level0, level1, bridge) Tries to build the given road draft along the given line. Returns true if building was successful. For this option to work _level0_ and _level1_ must be equal. Default is **false**.
bool function Builder.isTreeBuildable(draft draft, x, y) Checks whether the specified tree draft can be built at the specified position.
number function Builder.getTreePrice(draft draft, x, y) Returns the price of the tree. May change with time.
bool function Builder.buildTree(draft draft, x, y, frame) Tries to build the given tree draft at the specified position x, y and return true if this was successful. If frame is specified it also tries to set the frame of the tree accordingly. will be picked if it isn't specified.
bool function Builder.isRoadDecoBuildable(draft draft, x, y, level) Returns true if the given road decoration can be applied to the road at the specified location. level.
number function Builder.getRoadDecoPrice(draft draft, x, y, level) Returns the price of the road deco. May change with time. level.
bool function Builder.buildRoadDeco(draft draft, x, y, level) Tries to build the given road decoration draft on the road on the specified location. Returns true if this was successful. level.
bool function Builder.isGroundBuildable(draft draft, x, y) Returns true if the ground draft can be built at the given location. **true** for water or **false** for land. A generic ground draft will be used then.
number function Builder.getGroundPrice(draft draft, x, y) Returns the price of the ground. May change with time. **true** for water or **false** for land. A generic ground draft will be used then.
bool function Builder.buildGround(draft draft, x, y) Builds the specified ground draft and returns true if building was successful. **true** for water or **false** for land. A generic ground draft will be used then.
void function Builder.remove(x, y) Removes anything from the specified location.
void function B:init(_city, _modifier) Attachment
number function Builder.getBuildingPrice( draft, x, y) Returns the price of the building. May change with time.
bool function Builder.buildBuilding( draft, x, y, frame) Tries to build the given building draft at the specified position and sets it's frame if a frame was specified. Returns true if the build was was successful. was specified a random frame will be used (in case the building has multiple frames).
void function Builder.getBuildingUpgradePrice(draft, x, y)
void function Builder.buildBuildingUpgrade(draft, x, y)
void function Builder.removeBuildingUpgrade(draft, x, y)
bool function Builder.isRoadBuildable(draft draft, x0, y0, x1, y1, level0, level1, bridge) Checks whether the specified road draft can be build along the given line x0,y0 - x1,y1. To build a bridge manually you have to set level0 = level1 and bridge = true Only a single lane will be built so a valid line has to fulfill the property x0 == x1 or y0 == y1 For this option to work _level0_ and _level1_ must be equal. Default is **false**.
number function Builder.getRoadPrice( draft, x0, y0, x1, y1, level0, level1, bridge) Returns the price of the road. May change with time. For this option to work _level0_ and _level1_ must be equal. Default is **false**.
bool function Builder.buildRoad(draft draft, x0, y0, x1, y1, level0, level1, bridge) Tries to build the given road draft along the given line. Returns true if building was successful. For this option to work _level0_ and _level1_ must be equal. Default is **false**.
bool function Builder.isTreeBuildable(draft draft, x, y) Checks whether the specified tree draft can be built at the specified position.
number function Builder.getTreePrice(draft draft, x, y) Returns the price of the tree. May change with time.
bool function Builder.buildTree(draft draft, x, y, frame) Tries to build the given tree draft at the specified position x, y and return true if this was successful. If frame is specified it also tries to set the frame of the tree accordingly. will be picked if it isn't specified.
bool function Builder.isRoadDecoBuildable(draft draft, x, y, level) Returns true if the given road decoration can be applied to the road at the specified location. level.
number function Builder.getRoadDecoPrice(draft draft, x, y, level) Returns the price of the road deco. May change with time. level.
bool function Builder.buildRoadDeco(draft draft, x, y, level) Tries to build the given road decoration draft on the road on the specified location. Returns true if this was successful. level.
bool function Builder.isGroundBuildable(draft draft, x, y) Returns true if the ground draft can be built at the given location. **true** for water or **false** for land. A generic ground draft will be used then.
number function Builder.getGroundPrice(draft draft, x, y) Returns the price of the ground. May change with time. **true** for water or **false** for land. A generic ground draft will be used then.
bool function Builder.buildGround(draft draft, x, y) Builds the specified ground draft and returns true if building was successful. **true** for water or **false** for land. A generic ground draft will be used then.
void function Builder.remove(x, y) Removes anything from the specified location.
void function B:init(_city, _modifier) Attachment