Lua API documentation [550]

The Lua scripting language allows you to give your plugin more advanced features.

Moderator: Plugin Moderators

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 776
Joined: Sun May 28, 2017 0:07
Location: Retrophrenology
Plugins: Show
Version: Beta

Lua API documentation [550]

Post by FranchuFranchu » Fri Oct 19, 2018 1:07

Show
Array
function Array:new(number length, anything init)
Creates a new array object of given size. The array is initialized with nilif not init value is specified
Returns: array
function Array:construct(anything ...)
Creates an array directly from a list of parameters.You may use the alias Array(...) instead.
Returns: array
function Array:get(number i)
Returns the content of the array at the i-th position. Take care of that thefirst position has index 0 (instead of 1).
Returns: anything
function Array:set(number i, anything v)
Sets the content of the array at the i-th position to v. Take care of thatthe first position has index 0 (instead of 1).
Returns: None
function Array:forEach(function foo)
Contains the length of the array. This is not a function. Don't modify it.You may use the alias #array instead of array.lengthCalls function foo(value, index) on every element of the array.
Returns: number
function Array:fill(anything anything value)
Sets all entries of the array to the given value.
Returns: None
function Array:copy()
Creates a new array of same length and contents.
Returns: array
function Array:copyTo(number start, array other, number number startOther, number length)
Copies this array into another one using the specified starting index forreading, writing and the provided length. This method uses hardwareacceleration if possible.
Returns: None
function Array:iter()
Allows iteration using a for loop. Returns e, i for each iteration.Usage:for e,i in array:iter() do print(e,i) end
Returns: iterator
function Array:__tostring()
Returns a readable representation of the array.Usage: tostring(array)
Returns: string
function Array:__index(k)
Index aslias for get and set methdos.Usage: array[7] = array[5] --Equivalent to array:set(7, array:get(5))For performance intensive tasks consider to favor the usage of set and getmethods instead as index accesses need more resolving steps during runtime.
Returns: None
function Array:__newindex(k, anything v)
[No documentation]
Returns: None
function Array:__len()
[No documentation]
Returns: None
function A.newCompat(number length, anythnumber ing number innumber it)
Attachment
Returns: None
Show
Builder
function Builder.isBuildingBuildable(draft draft, number x, number y)
Checks whether the specified building draft can be built at the givenposition x, y. Returns true iff the building can be built.
Returns: bool
function Builder.buildBuilding(draft draft, number x, number y, number frame)
Tries to build the given building draft at the specified position andsets it's frame if a frame was specified. Returns true iff the build waswas successful.
Returns: bool
function Builder.isRoadBuildable(draft draft, number number x0, number number y0, number number x1, number number y1, number level0, number level1, bool bridge)
Checks whether the specified road draft can be build along the given linex0,y0 - x1,y1. To build a bridge manually you have to setlevel0 = level1 and bridge = trueOnly a single lane will be built so a valid line has to fulfill the propertyx0 == x1 or y0 == y1
Returns: bool
function Builder.buildRoad(draft draft, number number x0, number number y0, number number x1, number number y1, number level0, number level1, bool bridge)
Tries to build the given road draft along the given line. Returns true ifbuilding was successful.
Returns: bool
function Builder.isTreeBuildable(draft draft, number x, number y)
Checks whether the specified tree draft can be built at the specifiedposition x, y.
Returns: bool
function Builder.buildTree(draft draft, number x, number y, number frame)
Tries to build the given tree draft at the specified position x, y andreturn true iff this was successful. If frame is specified it also triesto set the frame of the tree accordingly.
Returns: bool
function Builder.isRoadDecoBuildable(draft draft, number x, number y, number level)
Checks whether the given road decoration draft can be applied to the road atthe specified location x, y, level. Returns true iff it can.
Returns: bool
function Builder.buildRoadDeco(draft draft, number x, number y, number level)
Tries to build the given road decoration draft on the road at the specifiedlocation x, y, level. Returns true iff this was successful.
Returns: bool
function Builder.isGroundBuildable(draft draft, int x, int y)
Returns true if the given draft can be built at the given location.
Returns: bool
function Builder.buildGround(draft draft, int x, int y)
Builds the specified ground draft and returns true iff building wassuccessful.
Returns: bool
function Builder.remove(number x, number y)
Removes anything from the specified location x, y.
Returns: None
function B:init(_citnumber y, _modifier)
Attachment
Returns: None
Show
Channel
function Channel:new()
[No documentation]
Returns: Unknown
function Channel:clear()
[No documentation]
Returns: None
function Channel:receive(tag)
[No documentation]
Returns: None
function Channel:receiveAll(tag, f)
[No documentation]
Returns: None
function Channel:receiveAll(tag, f)
[No documentation]
Returns: None
Show
City
function City.alert(integer actionPlaceTinteger ype, integer x, integer y)
Potential disaster names as used by City.getDisaster and City.issueDisaster.Constants used for action place markers.Sets an action marker (or removes the one previously set there).
Returns: Unknown
function City.getName()
Name of the current city
Returns: string
function City.setName(string newName)
Sets a new city name
Returns: None
function City.getRotation()
Returns the current rotation of the city. City rotation is expressed with aninteger number 0 (unrotated), ..., 3
Returns: number {0, 1, 2, 3}
function City.setRotation(r)
Sets the rotation of the city@r number {0, 1, 2, 3}
Returns: None
function City.getWidth()
Width of the city in tiles
Returns: number
function City.getHeight()
Height of the city in tiles
Returns: number
function City.getSeed()
Returns the seed that was used to generate the city
Returns: string
function City.getAuthor()
Returns the name of the author that the player entered
Returns: string
function City.isSandbox()
Determines whether the city is in sandbox mode
Returns: bool
function City.getMoney()
Estate of the city
Returns: number
function City.getMoney()
Spends some money. If x, y is specified it will show a red price at thatlocation.
Returns: None
function City.earnMoney(number amount, optional x, optional y, showOverlaoptional y)
Earns some money. If x, y is provided (and >= 0) then the money will bedrawn as if it was earned at the provided place (green text).If showOverlay is true and overlay for the money will be shown(default is false).Requires privileged rights.
Returns: None
function City.getCurrency(string name)
Returns the available amount of the currency of the given name.E.g. City.getCurreny('bus currency')
Returns: number, string
function City.getCurrency(string name)
Spends amount of the currency named name.
Returns: None
function City.earnCurrency(string name, number amount)
Earns amount of the currency named name.Requires privileged rights.
Returns: None
function City.getPeople(number level)
Returns the number of the specified level (0, 1 or 2). Returns the number ofall people if no level was specified.
Returns: number
function City.addPeople(number level, number amount)
[No documentation]
Returns: None
function City.getStorage()
Use this storage table to save things city wide
Returns: table
function City.getFunVar(string name, number fallbackValue)
Returns the value of the classic fun variable of the given name orfallbackValue if no such variable has been defined, yet.fallbackValue is 0 by default.Note that fun variables can only contain numbers. Use City.getStorage()or TheoTown.getStorage() to store more fancy stuff.Global fun variables are indicated by a leading ! in it's name.
Returns: number
function City.setFunVar(string name, number value)
Sets the value of a classic fun variable called name.Note that fun variables can only contain numbers. Use City.getStorage()or TheoTown.getStorage() to store more fancy stuff.Global fun variables are indicated by a leading ! in it's name.
Returns: None
function City.getTime()
[No documentation]
Returns: None
function City.getAbsoluteDay()
[No documentation]
Returns: None
function City.getDay()
[No documentation]
Returns: None
function City.getMonth()
[No documentation]
Returns: None
function City.getYear()
[No documentation]
Returns: None
function City.countBuildings(draft)
[No documentation]
Returns: None
function City.getBuilding(indeoptional x, draft)
[No documentation]
Returns: None
function City.forEachBuilding(f, draft)
[No documentation]
Returns: None
function City.countRoads(draft)
[No documentation]
Returns: None
function City.getRoad(indeoptional x, draft)
[No documentation]
Returns: None
function City.forEachRoad(f, draft)
[No documentation]
Returns: None
function City.spawnCar(draft carDraft, number startX, number startY, number targetX, number targetY, optional frame)
Spawns a car at a given position / position of a building that drives tothe given target / building at the target.The car will actually not spawned immediately but after a path has beencalculated. This happens asynchronously since path calculation isheavy on computation.You can provide a frame to determine the actualy type of the car. It will berandom by default.
Returns: None
function City.getDisaster()
Returns the name of the curretly active disaster or nil if no disaster isis active right now.
Returns: string
function City.issueDisaster(string name, number x, number y)
Issues the disaster of the given name at the given position x, y.Returns true iff disaster was issued successfully.
Returns: bool
function City.getView()
Returns the tile position the camera is currently looking at as well asthe current scale. Format: x, y, scale
Returns: number, number, number
function City.setView(number x, number y, number scale)
Sets the view to a specified tile x, y using the provided scale. If no scaleis provided the current scale will be used.Scale 1 means no scaling, 2 times scaling etc.
Returns: None
function City.save(bool enforce)
[No documentation]
Returns: None
function City.load(string path, bool overwrite, bool private)
[No documentation]
Returns: None
function City.getCities()
[No documentation]
Returns: None
function C:init(orig, origBuilder)
Attachment
Returns: None
Show
Debug
function Debug.log(... message, ...)
Logs a message into the script internal log.
Returns: Unknown
function Debug.toast(... message, ...)
Shows the specified message as toast overlay.It's discouraged to call this function too often since new messages arepostponsed if a previous message is still displayed.
Returns: None
function Debug.info(... message, ...)
Logs a message into the debug overlay of the game. This function is meantto be used within the script:update() method since the log is cleared everyframe.Calling this function opens the debug overlay automatically, so ensure toremove it in your production code.
Returns: None
Last edited by FranchuFranchu on Wed Oct 31, 2018 0:12, edited 1 time in total.
Currently Conlanging

......Affirmative=Positive=True=Yeah=Yes=OK=K=Potassium=K=0°K=-237°C

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 776
Joined: Sun May 28, 2017 0:07
Location: Retrophrenology
Plugins: Show
Version: Beta

Re: Lua API documentation [550]

Post by FranchuFranchu » Fri Oct 19, 2018 1:09

[/spoiler]
Show
Draft
function Draft.getDraft(string id)
Returns the draft of the given id. nil is returned if no draft of the givenid was found.
Returns: draft
function Draft.getDrafts(string tag)
Returns a list of drafts that have the given tag defined. If no tag isprovided this function returns a list of all available drafts.
Returns: list
function Draft:getId()
[No documentation]
Returns: None
function Draft:getTitle()
[No documentation]
Returns: None
function Draft:getText()
[No documentation]
Returns: None
function Draft:getAuthor()
[No documentation]
Returns: None
function Draft:getType()
[No documentation]
Returns: None
function Draft:isBuilding()
[No documentation]
Returns: None
function Draft:isRCI()
[No documentation]
Returns: None
function Draft:isRoad()
[No documentation]
Returns: None
function Draft:isRoadDecoration()
[No documentation]
Returns: None
function Draft:isAnimation()
[No documentation]
Returns: None
function Draft:isGround()
[No documentation]
Returns: None
function Draft:isCar()
[No documentation]
Returns: None
function Draft:isTree()
[No documentation]
Returns: None
function Draft:isTemplate()
[No documentation]
Returns: None
function Draft:getFrameCount()
[No documentation]
Returns: None
function Draft:getFrame(i)
[No documentation]
Returns: None
function Draft:setFrame(i, f) self.orig.frames[i + 1] = f
[No documentation]
Returns: None
function Draft:getPrice()
[No documentation]
Returns: None
function Draft:getMonthlyPrice()
[No documentation]
Returns: None
function Draft:getWidth()
[No documentation]
Returns: None
function Draft:getHeight()
[No documentation]
Returns: None
function Draft:setVisible(state) self.orig.hstring idden = not state
[No documentation]
Returns: None
function Draft:isVisible()
[No documentation]
Returns: None
function Draft:getMeta()
Returns the meta table of the draft if available. nil otherwise.
Returns: table
function Draft:getContent()
For template and data drafts only: returns the raw json definitionof the draft.
Returns: table
function Draft:__tostring()
Returns a readable representation of the draft.
Returns: string
function D:new(orig)
Attachment
Returns: None
function D:init()
[No documentation]
Returns: None
Show
Drawing
function Drawing.getSize()
Returns the current screen size width, height in pixels.Note that the result may change over time due to resolution changes.
Returns: number, number
function Drawing.setScale(sx, sy)
[No documentation]
Returns: None
function Drawing.getScale()
[No documentation]
Returns: None
function Drawing.setTile(tileX, tileY, offsetX, offsetY)
[No documentation]
Returns: None
function Drawing.reset()
[No documentation]
Returns: None
function Drawing.setColor(r, g, b)
[No documentation]
Returns: None
function Drawing.getColor()
[No documentation]
Returns: None
function Drawing.setAlpha(alpha)
[No documentation]
Returns: None
function Drawing.getAlpha()
[No documentation]
Returns: None
function Drawing.getTextSize(text, font)
[No documentation]
Returns: None
function Drawing.getImageSize(frame)
[No documentation]
Returns: None
function Drawing.drawText(text, x, y, font)
[No documentation]
Returns: None
function Drawing.drawImage(frame, x, y)
[No documentation]
Returns: None
function Drawing.drawLine(x0, y0, x1, y1, width)
[No documentation]
Returns: None
Show
GUI
function GUI.getMaster()
Returns the root gui object.
Returns: gadget
function GUI.find(id)
Finds a gadget by it's id.
Returns: gadget
function G._init(m)
Attachment
Returns: None
Show
HalloweenScript
function script:init()
[No documentation]
Returns: Unknown
function script:daily(x, y)
[No documentation]
Returns: None
function script:draw(x, y)
[No documentation]
Returns: None
function script:click(x, y)
[No documentation]
Returns: None
Show
List
function List:new(anything ...)
Creates a new list object that contains the provided parameters.You may use the alias List(...) instead.
Returns: list
function List:fromArray(array arr)
Creates a new list from an array.
Returns: list
function List:add(anything e)
Appends an object e to the end of the list. Returns the index of e afterinsertion.
Returns: number
function List:addFirst(anything e)
Appends object e to the front of the list. Returns the index of e (always 0).
Returns: number
function List:addAt(anythnumber ing e, number i)
Inserts object e at the specified index i. Returns i afterwards.
Returns: number
function List:forEach(function f)
Calls function f(element, index) for each object of the list.
Returns: None
function List:find(anythnumber ing e)
Searches for object e in the list and returns the index of the firstoccurence.If no such object was found in the list the method returns -1.
Returns: number
function List:contains(anythnumber ing e)
Determines whether object e is in the list
Returns: bool
function List:removeAt(number i)
Removes the object at the given index i and returns the removed object.
Returns: anything
function List:remove(anythnumber ing e)
Finds and removes the first occurence of object e in the list. It returnsthe removed object or false if no object has been removed.
Returns: anything
function List:removeFirst()
Removes and returns the first object of the list.
Returns: anything
function List:removeLast()
Removes and returns the last object of the list.
Returns: anything
function List:first()
Returns the first object of the list.Equivalent to list:get(0)
Returns: anything
function List:last()
Returns the last object of the list.Equivalent to list:get(list:size()-1)
Returns: anything
function List:isEmpty()
Returns true iff the list is empty, false otherwise.Equivalent to list:size() == 0
Returns: bool
function List:size()
Returns the number of objects in the list.You may use the alist #list instead of list:size()
Returns: number
function List:clear()
Removes all objects from the list and sets it's size to 0. Returns thenumber of objects that the list contained previously.
Returns: number
function List:get(number i)
Returns the object at index i. Note that index counting starts at 0 solist:get(0) returns the first object of the list.
Returns: anything
function List:set(number i, anything v)
Replaces the object at index i with the given object v and returns it.
Returns: anything
function List:values()
Returns the table that stores all objects of the list. Modifications to thistable are discouraged as it may break the list.
Returns: table
function List:filter(function f)
Creates and returns a list that only contains the objects the function freturned true for.Usage: List(1,2,3):filter(function(n) return n ~= 2 end)
Returns: list
function List:map(function f)
Applies a function f on all items of the list and returns it as a new list.Usage: List(1,2,3):map(function(n) return n + 1 end)
Returns: list
function List:addAll(othanythnumber ing erLnumber ist)
Appends all objects of another list to this list.
Returns: None
function List:copy()
Creates a copy of this list that holds the same objects.
Returns: list
function List:toArray()
Creates a array that contains all objects of the list.
Returns: array
function List:iter()
Allows iteration using a for loop. Returns e, i for each iteration.Usage:for e,i in list:iter() do print(e,i) end
Returns: iterator
function List:pick()
Returns a random element of the list. nil if the list is empty.
Returns: anything
function List:__tostring()
Returns a readable representation of the list.
Returns: string
function List:__index(k)
Index accessor methods allow you to access elements of the list directly via[] operator.For example list[0] = list[1]is equivalent to list:set(0, list:get(1))Due to the overhead of this operator it's recommended to use get and setmethods instead in time critical applications.
Returns: None
function List:__newindex(k, anything v)
[No documentation]
Returns: None
Show
Runtime
function Runtime.getName()
Name of the application, should be 'TheoTown'
Returns: string
function Runtime.getVersion()
Current version of TheoTown, e.g. 1.5.15
Returns: string
function Runtime.getVersionCode()
Current version of TheoTown as number, e.g. 515
Returns: number
function Runtime.getId()
Package id of the app, should be 'info.flowersoft.theotown.theotown'
Returns: string
function Runtime.getAndroidVersion()
Returns the android version code and name of the device.
Returns: number, string
function Runtime.getModel()
Returns model name and manufacturer of the device.
Returns: string, string
function Runtime.isDebug()
Always false
Returns: bool
function Runtime.getTime()
Unix timestamp in milliseconds
Returns: number
function fromJson(string json)
Converts a json string into a lua table.
Returns: table
function toJson(table tbl)
Converts a table into a json string.
Returns: string
function getUuid()
Returns a random uuid string.
Returns: string
function loadText(path)
[No documentation]
Returns: None
function saveText(path, text)
[No documentation]
Returns: None
function downloadText(url, handler)
handler(error, result)
Returns: None
function postpone(foo, delayMS)
[No documentation]
Returns: None
function R:init(config)
Attachment
Returns: None
Currently Conlanging

......Affirmative=Positive=True=Yeah=Yes=OK=K=Potassium=K=0°K=-237°C

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 776
Joined: Sun May 28, 2017 0:07
Location: Retrophrenology
Plugins: Show
Version: Beta

Re: Lua API documentation [550]

Post by FranchuFranchu » Fri Oct 19, 2018 1:14

[/spoiler]
Show
Script
function script:init()
Will be called for building and road drafts right after placement.Will be called for building and road drafts right after construction.That is immediately after placements for roads and for buildings witht zerobuildtime.Will be called for building with car spawner whenever a car was spawned.Will be called for building with car spawner whenever a car reached it'starget.Will be called for building with car spawner whenever a car was despawned.Will be called for scripts attached to a generic tool when users selectsthe tool.Will be called once after all drafts and scripts have been loaded.
Returns: Unknown
function script:lateInit()
Will be called once after script:init() has been called on all scripts. Usethis method for things that relay on other scripts' setup.
Returns: None
function script:isBuildable(number x, number y, number level)
For buildings and roads only:Will be queried to determine if a building/road can be built at a specificlocation. To prevent buildability just let it return false.Is also queried for custom tools to determine buildability.
Returns: None
function script:daily(number x, number y, number level)
Will be called on a daily basis for every building or road that areinstances of the owning draft. Level is 0 for buildings.
Returns: None
function script:click(number x, number y, number level)
Will be called when the user taps on a building or road that is aninstance of the owning draft. Level is 0 for buildings.
Returns: None
function script:event(number x, number y, number level, number event)
Will be called for building/road events of instances of the owning draft.Level is 0 for buildings.
Returns: None
function script:draw(number x, number y, number level)
Will be called after a building/road instance has been drawn.Will also be called on all visible tiles for custom tools.
Returns: None
function script:random(number x, number y)
Will be called every day for scripts whose owning draft is a building orroad. x and y is a random (valid) postion on the map.
Returns: None
function script:nextDay()
Will be called on a daily basis for each script.
Returns: None
function script:nextMonth()
Will be called on a monthly basis for each script.
Returns: None
function script:nextYear()
Will be called on a yearly basis for each script.
Returns: None
function script:update()
Will be called per frame for each script while a city is open. Can be usedto draw stuff on the screen (under the UI).Use overlay() do draw on top of UI and/or outside of cities.
Returns: None
function script:click(number x, number y)
Will be called when users taps on a building/road of this draft while beingin default tool.Return false to prevent opening the default tile dialog.You should favor this method over earlyTap() and tap() as they operateindepently of tile dialog and selected tool and don't take the own draftinto consideration.This method will also be called for custom tools if user taps on a tileand script:isBuildable() returned true for it.
Returns: None
function script:earlyTap(number tileX,number tileY,number x,number y)
Will be called when the user taps on the map. Will be called just beforethe tap is handled by the current tool.
Returns: None
function script:tap(number tileX,number tileY,number x,number y)
Will be called when the user taps on the map. Will be called just afterthe tap is handled by the current tool.
Returns: None
function script:enterCity()
Will be called when the user enters a city.
Returns: None
function script:leaveCity()
Will be called when the user leaves the city. Don't rely on this method topermanently save state since there's no guarantee that this method will becalled.
Returns: None
function script:save()
Will be called just before the city is saved.
Returns: None
function script:enable()
Will be called when this script is about to be enabled. Scripts are enabledby definiton right after their creation so this method won't be called then.
Returns: None
function script:disable()
Will be called when this script is about to be disabled.
Returns: None
function script:overlay()
Will be called once per frame after UI has been drawn. Will also be calledoutside of cities.
Returns: None
function script:enterStage()
[No documentation]
Returns: None
function script:leaveStage()
[No documentation]
Returns: None
function Script.getScript()
Returns the current script or nil if no script is currently running
Returns: script
function Script.getScripts(anything tag)
Returns a list of all scripts, or, if tag is specified, a list of allscripts that defined the given tag.Don't manipulate the returned list directly.
Returns: list
function Script:getId()
Every script is uniquely identified by a single number.
Returns: number
function Script:getDraft()
Returns the draft the script is attached to. Every script instance isattached to exactly one draft. However, multiple instances of the samescript may be attached to different drafts.
Returns: draft
function Script:getName()
Returns the name of the script. E.g. the name of a scriptfolder/test.lua is just test
Returns: string
function Script:getPath()
Returns the relative path of the script.
Returns: string
function Script:getLocation()
Returns a readable location identifier that contains the draft id.
Returns: string
function Script:getParents()
Returns a list of all parent scripts.
Returns: list
function Script:getParent()
Returns the parent script, if there is any. Nil otherwise.A parent script is the script that instantiated this script usingscript:addScript()Scripts are usually not instantiated by other scripts.
Returns: script
function Script:setActive(bool state)
Activates or disables the script. No event methods will be called ondisabled scripts. A disabled script cannot re-enable itself since it won'tbe updated anymore.
Returns: None
function Script:isActive()
Determines whether the script is active right now.
Returns: bool
function Script:getChannel()
Returns the communication channel of this script. You can use channels tocommunicate between scripts.
Returns: channel
function Script:addTag(anything tag)
Adds a tag to this script. Tags can be used to find scripts by usinggetScripts(tag)
Returns: None
function Script:getTags()
Returns a set that contains the tags that has been defined for that script.
Returns: set
function Script:broadcast(anything anything msgTag, anything msg, anything scriptTag)
Broadcasts a message msg of the given message tag msgTag to all otherscripts.If a script tag scriptTag is provided only scripts with that tag willreceive the message. Using a script tag is recommended to avoid spammingunparticipated scripts.The sender script won't receive the message.
Returns: None
function Script:addScript(string name, draft draft, function initializer)
Adds a script to a draft. Only call this method in the init or lateInitmethods to ensure that it will be executed correctly.However, init and/or lateInit might not be called on the new scriptautomatically.Format of initializer: initializer(script)If no initializer is provided the own initializer will be used.Returns the newly created script.
Returns: script
function S:new(string name, path, draft draft, orig, parent)
Attachment
Returns: None
function S:__tostring()
[No documentation]
Returns: None
function S:baseInit()
[No documentation]
Returns: None
Show
Set
function Set:new(anything ...)
Creates a new set and inserts the provided parametersYou may use the alias Set(...) instead.
Returns: set
function Set:add(anything e)
Inserts an object into the set and returns true if the object wasn't in theset before, false otherwise.
Returns: bool
function Set:addAll(set s)
Inserts all objects of a provided set into the set.
Returns: None
function Set:contains(anything e)
Checks whether an object e is in the set. Returns true if there is, falseotherwise.
Returns: bool
function Set:remove(anything e)
Removes an object e from the set. Returns true if such an object has been inthe set, false otherwise.
Returns: bool
function Set:removeAll(set s)
Removes all objects of a provided set from this set.
Returns: None
function Set:size()
Returns the number of objects in the set.You may use the alias #set instead of set:size()
Returns: number
function Set:copy()
Creates a copy of the set and returns it.
Returns: set
function Set:forEach(function f)
Calls function f(e) for each object in the set.
Returns: None
function Set:iter()
Allows iteration using a for loop. Returns e, i for each iteration.Usage:for e in set:iter() do print(e) end
Returns: iterator
function Set.union(set a, set b)
Returns a new set that contains all objects of the sets a and b.You may use alias a + b instead of Set.union(a, b)
Returns: set
function Set.subtract(set a, set b)
Returns a new set that contains all objects of set a except those that arealso in set b.You may use alias a - b instead of Set.subtract(a, b)
Returns: set
function Set.cut(set a, set b)
Returns a new set that contains all objects that are in both sets, a and b.You may use alias a * b instead of Set.cut(a, b)
Returns: set
function Set:__tostring()
Returns a readable representation of the set.
Returns: string
function Set:__eq(set o)
Returns true if this and the other set contain the same objects.You may use alias a == b instead of a:__eq(b)
Returns: bool
Show
TheoTown
function TheoTown.getDiamonds()
Returns the number of diamonds that the user currently has.
Returns: number
function TheoTown.getDiamonds()
Spends amount diamonds if possible. Returns true iff spending was successful,false otherwise.
Returns: None
function TheoTown.getStorage()
Returns a game wide storage table. Use it to save data permanently accrossall cities.
Returns: table
function TheoTown.registerCommand(string name, function f)
Registers a function that can then by called from console.Usage: TheoTown.registerCommand('test', function(name, arg) return arg end)Instead of a name you can provide a function that returns true for commandsthe second function should handle.
Returns: None
function TheoTown.getExperiment(string name)
[No documentation]
Returns: None
function TheoTown.setExperiment(string name, value)
[No documentation]
Returns: None
function TheoTown.translate(id)
[No documentation]
Returns: None
function TheoTown.playSound(id, volume)
[No documentation]
Returns: None
function TheoTown.getId()
[No documentation]
Returns: None
function TheoTown.getConfig(string name)
[No documentation]
Returns: None
function isfunction(function f)
[No documentation]
Returns: None
function isnumber(n)
[No documentation]
Returns: None
function isstring(s)
[No documentation]
Returns: None
function istable(t)
[No documentation]
Returns: None
function isnil(n)
[No documentation]
Returns: None
function isbool(b)
[No documentation]
Returns: None
function switch(value, ...)
[No documentation]
Returns: None
function math.randomrange(l, u)
[No documentation]
Returns: None
function math.map(v, vl, vu, l, u)
[No documentation]
Returns: None
function math.lin(v, l, u)
[No documentation]
Returns: None
function string:split(sep)
[No documentation]
Returns: None
Currently Conlanging

......Affirmative=Positive=True=Yeah=Yes=OK=K=Potassium=K=0°K=-237°C

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 776
Joined: Sun May 28, 2017 0:07
Location: Retrophrenology
Plugins: Show
Version: Beta

Re: Lua API documentation [550]

Post by FranchuFranchu » Wed Oct 31, 2018 0:17

[/spoiler]
Show
Tile
function Tile.isValid(x, y)
Influence types.
Returns: Unknown
function Tile.isWater(x, y)
[No documentation]
Returns: None
function Tile.isLand(x, y)
[No documentation]
Returns: None
function Tile.isTree(x, y)
[No documentation]
Returns: None
function Tile.getGroundDraft(x, y)
[No documentation]
Returns: None
function City.getInfluence(infType, x, y)
[No documentation]
Returns: None
function Tile.isBuilding(x, y)
[No documentation]
Returns: None
function Tile.isBuildingInConstruction(x, y)
[No documentation]
Returns: None
function Tile.hasBuildingNeededRoad(x, y)
[No documentation]
Returns: None
function Tile.hasBuildingRoad(x, y)
[No documentation]
Returns: None
function Tile.isBuildingBurning(x, y)
[No documentation]
Returns: None
function Tile.isBuildingIll(x, y)
[No documentation]
Returns: None
function Tile.isBuildingFullOfWaste(x, y)
[No documentation]
Returns: None
function Tile.isBuildingFullOfDeadPeople(x, y)
[No documentation]
Returns: None
function Tile.isBuildingEmpty(x, y)
[No documentation]
Returns: None
function Tile.getBuildingFrame(x, y)
[No documentation]
Returns: None
function Tile.setBuildingFrame(x, y, frame)
[No documentation]
Returns: None
function Tile.getBuildingDraft(x, y)
[No documentation]
Returns: None
function Tile.getBuildingXY(x, y)
[No documentation]
Returns: None
function Tile.getBuildingStorage(x, y)
[No documentation]
Returns: None
function Tile.hasBuildingUpgrade(upgrade, x, y)
[No documentation]
Returns: None
function Tile.isRoad(x, y, level)
[No documentation]
Returns: None
function Tile.hasRoad(x, y)
[No documentation]
Returns: None
function Tile.getRoadFrame(x, y, level)
[No documentation]
Returns: None
function Tile.getRoadDraft(x, y, level)
[No documentation]
Returns: None
function Tile.getRoadStorage(x, y, level)
[No documentation]
Returns: None
function Tile.getRoadCarCount(x, y, level)
[No documentation]
Returns: None
function Tile.isRoadDeco(x, y, level)
[No documentation]
Returns: None
function Tile.getRoadDecoDraft(x, y, level)
[No documentation]
Returns: None
function Tile.setRoadDecoDraft(draft, x, y, level)
[No documentation]
Returns: None
function Tile.pack(x, y)
[No documentation]
Returns: None
function Tile.unpack(xy)
[No documentation]
Returns: None
function T:init(orig)
Attachment
Returns: None
Show
Vector
function Vector:new(number x, number y, number z)
Creates a new vector out of the components x, y, z.You may use the alias Vector(x, y, z) instead.
Returns: vector
function Vector:length()
Returns the length of the vector.
Returns: number
function Vector.dot(vector a, vector b)
Returns the dot product of two vectors a and b.
Returns: number
function Vector.cross(vector a, vector b)
Returns the cross product of two vectors a and b.
Returns: vector
function Vector:normalized()
Returns a normalized vector that points in the same direction as self.
Returns: vector
function Vector:copy()
Returns a copy of the vector.
Returns: vector
function Vector:__tostring()
Returns a readable representation of the vector.
Returns: number
function Vector:__add(o)
Support for arithmetic operations on vectors likea + 2 * b
Returns: None
function Vector:__mul(o)
[No documentation]
Returns: None
function Vector:__div(o)
[No documentation]
Returns: None
function Vector:__sub(o)
[No documentation]
Returns: None
function Vector:__unm()
[No documentation]
Returns: None
function Vector:__eq(o)
[No documentation]
Returns: None
Currently Conlanging

......Affirmative=Positive=True=Yeah=Yes=OK=K=Potassium=K=0°K=-237°C

Online
Imran M
Inhabitant of a Conurbation
Reactions:
Posts: 356
Joined: Wed Oct 24, 2018 13:41
Plugins: Show
Phone model: Huawei p8 lite

Re: Lua API documentation [550]

Post by Imran M » Fri Mar 08, 2019 20:00

In scratch, there's two blocks: broadcast message and when I receive message. Is there anything like that lua?
Secretary of Foreign Affairs of Adnijan.
I can do json files for people if they want me to (no fun).
My avatar is very original.

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 776
Joined: Sun May 28, 2017 0:07
Location: Retrophrenology
Plugins: Show
Version: Beta

Re: Lua API documentation [550]

Post by FranchuFranchu » Tue Mar 19, 2019 12:24

You can set a fun variable to nil at the start of the program, and then check every tick if it is not nil.
Setup

Code: Select all

function script:init()
     City.setFunVar("banana",nil)
end
To broadcast

Code: Select all

City.setFunVar("banana",42)
To receive

Code: Select all

function script:update()
     if City.getFunVar("banana",nil) ~= nil do
             --what to do when received
     end
end
Its probably very slow tho
Currently Conlanging

......Affirmative=Positive=True=Yeah=Yes=OK=K=Potassium=K=0°K=-237°C

User avatar
Lobby
Developer
Reactions:
Posts: 3248
Joined: Sun Oct 26, 2008 12:34
Plugins: Show
Version: Beta
Phone model: S7 edge

Re: Lua API documentation [550]

Post by Lobby » Wed Mar 20, 2019 0:19

In Lua there's a global namespace. So if you put something into a global variable you can read it from anywhere:

Code: Select all

globalvar = 42

function script:update()
  Debug.info('It has value ' .. globalvar)
end
If you use a public Array (TheoTown's replacement for Lists) you can enqueue and dequeue things from it.

However, the most easy thing would be to just call functions on the target script. In this context I'm not sure what the broadcast thing is doing.
...Have a nice stay

Post Reply Previous topicNext topic

Return to “Lua Scripting”

Who is online

Users browsing this forum: No registered users and 0 guests