Lua API documentation [741]

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: 787
Joined: Sun May 28, 2017 0:07
Location: In the blogosphere
Plugins: Show
Version: Beta

Platform

Plugin Creator

Lua API documentation [741]

#1

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

Show
Array
function Array:new(arr)
function Array:forEach(f)
function Array:map(f)
function Array:filter(f)
function Array:count(f)
function Array:add(e, i)
function Array:addAll(e, i)
function Array:find(e)
function Array:contains(e)
function Array:isEmpty()
function Array:removeAt(i)
function Array:remove(e)
function Array:clear()
function Array:sort(comp)
function Array:shuffle()
function Array:pick()
function Array:sub(s, l)
function Array:copy()
function mt:__tostring()
Show
Builder
bool function Builder.isBuildingBuildable( draft, x, y) Checks whether the specified building draft can be built at the given position x, y. Returns true iff the building can be built.
function Builder.buildBuilding(draft, x, y, frame)
function Builder.buildBuildingUpgrade(draft, x, y)
function Builder.isRoadBuildable(draft, x0, y0, x1, y1, level0, level1, bridge)
function Builder.buildRoad(draft, x0, y0, x1, y1, level0, level1, bridge)
function Builder.isTreeBuildable(draft, x, y)
function Builder.buildTree(draft, x, y, frame)
function Builder.isRoadDecoBuildable(draft, x, y, level)
function Builder.buildRoadDeco(draft, x, y, level)
function Builder.isGroundBuildable(draft, x, y)
function Builder.buildGround(draft, x, y)
function Builder.remove(x, y)
Show
Channel
function Channel:new()
function Channel:clear()
function Channel:receive(tag)
function Channel:receiveAll(tag, f)
function Channel:send(tag, value)
Show
City
function City.alert(integer actionPlaceTinteger ype, integer x, integer y) Sets an action marker (or removes the one previously set there).
string function City.getName() Name of the current city
string function City.getFileName() Returns the name of the file of the city.
function City.setName(string newName) Sets a new city name
number {0, 1, 2, 3} function City.getRotation() Returns the current rotation of the city. City rotation is expressed with an integer number 0 (unrotated), ..., 3
number {0, 1, 2, 3} function City.setRotation(r) Sets the rotation of the city
number function City.getWidth() Width of the city in tiles
number function City.getHeight() Height of the city in tiles
string function City.getSeed() Returns the seed that was used to generate the city
string function City.getAuthor() Returns the name of the author that the player entered
integer function City.getXp() Returns the amount of xp of the city.
bool function City.isSandbox() Determines whether the city is in sandbox mode
number function City.getMoney() Estate of the city
function City.spendMoney(amount, x, y) Spends some money. If x, y is specified it will show a red price at that location.
function City.earnMoney(amount, x, y, showOverlay) Earns some money. If x, y is provided (and >= 0) then the money will be drawn 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.
number, string function City.getCurrency(string name) Returns the available amount of the currency of the given name. E.g. City.getCurreny('bus currency')
function City.spendCurrency(string name, number amount) Spends amount of the currency named name.
function City.earnCurrency(string name, number amount) Earns amount of the currency named name. Requires privileged rights.
number function City.getPeople(number optional level) Returns the number of the specified level (0, 1 or 2). Returns the number of all people if no level was specified.
function City.addPeople(level, amount)
table function City.getStorage() Use this storage table to save things city wide
number function City.getFunVar(name, fallbackValue) Returns the value of the classic fun variable of the given name or fallbackValue 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.
function City.setFunVar(name, 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.
number function City.getTime() Returns the animation time of the game in milliseconds.
number function City.getAbsoluteDay() Returns the current absolute day of the city.
number function City.getDay() Returns the current day of the month of the city.
number function City.getMonth() Returns the current month of the city.
number function City.getYear() Returns the current year of the city.
function City.countBuildings(draft)
function City.getBuilding(index, draft)
function City.forEachBuilding(f, draft)
function City.countRoads(draft)
function City.getRoad(index, draft)
function City.forEachRoad(f, draft)
function City.spawnCar(carDraft, startX, startY, targetX, targetY, frame) Spawns a car at a given position / position of a building that drives to the given target / building at the target. The car will actually not spawned immediately but after a path has been calculated. This happens asynchronously since path calculation is heavy on computation. You can provide a frame to determine the actualy type of the car. It will be random by default.
string function City.getDisaster() Returns the name of the curretly active disaster or nil if no disaster is is active right now.
bool 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.
function City.enableDisaster(name, state) Enables or disables the automatic disaster of the given name.
number, number, number function City.getView() Returns the tile position the camera is currently looking at as well as the current scale. Format: x, y, scale
function City.setView(number x, number y, number optional scale) Sets the view to a specified tile x, y using the provided scale. If no scale is provided the current scale will be used. Scale 1 means no scaling, 2 times scaling etc.
function City.save(enforce) Saves the city if the user has autosave enabled. If enforce is set the city will even be saved if the user has autosave disabled.
function City.load(path, overwrite, private, target) Loads a city file provided by the plugin. path is the file of the city file (thus it includes the .city file ending). Prior to loading the city will be copied to maps or private maps folder first (depending on private value). If a city of similar file name already exists at that directory it will be overridden if overwrite flag is set. The target file name can be changed by specifieing a target name.
function City.getCities()
function City.setSpeed(s)
function City.getSpeed()
Show
Debug
function Debug.log(message, ...)
function Debug.toast(message, ...)
function Debug.info(message, ...)
Show
Draft
function Draft.getDraft(id)
function Draft.getDrafts(tag)
function Draft:getId()
function Draft:getTitle()
function Draft:getText()
function Draft:getAuthor()
function Draft:getType()
function Draft:isBuilding()
function Draft:isRCI()
function Draft:isResidential()
function Draft:isCommercial()
function Draft:isIndustrial()
function Draft:isRoad()
function Draft:isRoadDecoration()
function Draft:isAnimation()
function Draft:isGround()
function Draft:isCar()
function Draft:isTree()
function Draft:isTemplate()
function Draft:isCategory()
function Draft:getFrameCount()
function Draft:getFrame(i)
function Draft:getPrice()
function Draft:getMonthlyPrice()
function Draft:getWidth()
function Draft:getHeight()
function Draft:isVisible()
function Draft:getMeta()
function Draft:getContent()
function Draft:getScripts()
function Draft:__tostring()
function D:new(orig)
Show
Drawing
number, number function Drawing.getSize() Returns the current screen size width, height in pixels. Note that the result may change over time due to resolution changes.
function Drawing.setScale(sx, sy)
function Drawing.getScale()
function Drawing.setTile(tileX, tileY, offsetX, offsetY)
function Drawing.reset()
function Drawing.setColor(r, g, b)
function Drawing.getColor()
function Drawing.setAlpha(alpha)
function Drawing.getAlpha()
function Drawing.getTextSize(text, font)
function Drawing.getImageSize(frame)
function Drawing.drawText(text, x, y, font)
function Drawing.drawImage(frame, x, y)
function Drawing.drawImageRect(frame, x, y, w, h)
function Drawing.drawLine(x0, y0, x1, y1, width)
Show
GUI
function GUI.getMaster()
function GUI.find(id)
function G._init(m)
Show
HalloweenScript
Show
List
list function List:new(anything ...) Creates a new list object that contains the provided parameters. You may use the alias List(...) instead.
list function List:fromArray(array arr) Creates a new list from an array.
number function List:add(anything e) Appends an object e to the end of the list. Returns the index of e after insertion.
number function List:addFirst(anything e) Appends object e to the front of the list. Returns the index of e (always 0).
number function List:addAt(anythnumber ing e, number i) Inserts object e at the specified index i. Returns i afterwards.
function List:forEach(function f) Calls function f(element, index) for each object of the list.
number function List:find(anything e) Searches for object e in the list and returns the index of the first occurence. If no such object was found in the list the method returns -1.
bool function List:contains(anything e) Determines whether object e is in the list
anything function List:removeAt(number i) Removes the object at the given index i and returns the removed object.
anything function List:remove(anything e) Finds and removes the first occurence of object e in the list. It returns the removed object or false if no object has been removed.
anything function List:removeFirst() Removes and returns the first object of the list.
anything function List:removeLast() Removes and returns the last object of the list.
anything function List:first() Returns the first object of the list. Equivalent to list:get(0)
anything function List:last() Returns the last object of the list. Equivalent to list:get(list:size()-1)
bool function List:isEmpty() Returns true iff the list is empty, false otherwise. Equivalent to list:size() == 0
number function List:size() Returns the number of objects in the list. You may use the alist #list instead of list:size()
number function List:clear() Removes all objects from the list and sets it's size to 0. Returns the number of objects that the list contained previously.
anything function List:get(number i) Returns the object at index i. Note that index counting starts at 0 so list:get(0) returns the first object of the list.
anything function List:set(number i, anything v) Replaces the object at index i with the given object v and returns it.
table function List:values() Returns the table that stores all objects of the list. Modifications to this table are discouraged as it may break the list.
list function List:filter(function f) Creates and returns a list that only contains the objects the function f returned true for. Usage: List(1,2,3):filter(function(n) return n ~= 2 end)
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)
function List:addAll(list otherList) Appends all objects of another list to this list.
list function List:copy() Creates a copy of this list that holds the same objects.
array function List:toArray() Creates a array that contains all objects of the list.
iterator 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
anything function List:pick() Returns a random element of the list. nil if the list is empty.
string function List:__tostring() Returns a readable representation of the list.
function List:__index(k) is equivalent to list:set(0, list:get(1)) Due to the overhead of this operator it's recommended to use get and set methods instead in time critical applications.
function List:__newindex(k, v)
Last edited by FranchuFranchu on Sat Jun 22, 2019 17:04, edited 2 times in total.
</failedxss>

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 787
Joined: Sun May 28, 2017 0:07
Location: In the blogosphere
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua API documentation [550]

#2

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
</failedxss>

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 787
Joined: Sun May 28, 2017 0:07
Location: In the blogosphere
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua API documentation [550]

#3

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

Show
Runtime
function Runtime.getName()
function Runtime.getVersion()
function Runtime.getVersionCode()
function Runtime.getId()
function Runtime.getAndroidVersion()
function Runtime.getModel()
function Runtime.isDebug()
function Runtime.getTime()
function fromJson(json)
function toJson(tbl)
function getUuid()
function loadText(path)
function saveText(path, text)
function downloadText(url, handler)
function postpone(foo, delayMS)
Show
Script
Show
Set
set function Set:new(anything ...) Creates a new set and inserts the provided parameters You may use the alias Set(...) instead.
bool function Set:add(anything e) Inserts an object into the set and returns true if the object wasn't in the set before, false otherwise.
function Set:addAll(set s) Inserts all objects of a provided set into the set.
bool function Set:contains(anything e) Checks whether an object e is in the set. Returns true if there is, false otherwise.
bool function Set:remove(anything e) Removes an object e from the set. Returns true if such an object has been in the set, false otherwise.
function Set:removeAll(set s) Removes all objects of a provided set from this set.
number function Set:size() Returns the number of objects in the set. You may use the alias #set instead of set:size()
set function Set:copy() Creates a copy of the set and returns it.
function Set:forEach(function f) Calls function f(e) for each object in the set.
iterator 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
set 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)
set function Set.subtract(set a, set b) Returns a new set that contains all objects of set a except those that are also in set b. You may use alias a - b instead of Set.subtract(a, b)
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)
string function Set:__tostring() Returns a readable representation of the set.
bool 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)
Show
TheoTown
function TheoTown.getDiamonds()
function TheoTown.spendDiamonds(amount)
function TheoTown.getStorage()
function TheoTown.getFileStorage()
function TheoTown.registerCommand(name, f)
function TheoTown.getExperiment(name)
function TheoTown.setExperiment(name, value)
function TheoTown.translate(id)
function TheoTown.playSound(id, volume)
function TheoTown.getId()
function TheoTown.getConfig(name)
function isfunction(f)
function isnumber(n)
function isstring(s)
function istable(t)
function isnil(n)
function isbool(b)
function math.randomrange(l, u)
function math.map(v, vl, vu, l, u)
function math.lin(v, l, u)
function string:split(sep)
Show
Tile
function Tile.isValid(x, y)
function Tile.isWater(x, y)
function Tile.isLand(x, y)
function Tile.isTree(x, y)
function Tile.getGroundDraft(x, y)
function City.getInfluence(infType, x, y)
function Tile.isBuilding(x, y)
function Tile.isBuildingInConstruction(x, y)
function Tile.hasBuildingNeededRoad(x, y)
function Tile.hasBuildingRoad(x, y)
function Tile.isBuildingBurning(x, y)
function Tile.isBuildingIll(x, y)
function Tile.isBuildingFullOfWaste(x, y)
function Tile.isBuildingFullOfDeadPeople(x, y)
function Tile.isBuildingEmpty(x, y)
function Tile.extinguishBurningBuilding(x, y)
function Tile.getBuildingFrame(x, y)
function Tile.setBuildingFrame(x, y, frame)
function Tile.getBuildingDraft(x, y)
function Tile.getBuildingXY(x, y)
function Tile.getBuildingStorage(x, y)
function Tile.hasBuildingUpgrade(upgrade, x, y)
function Tile.isRoad(x, y, level)
function Tile.hasRoad(x, y)
function Tile.getRoadFrame(x, y, level)
function Tile.getRoadDraft(x, y, level)
function Tile.getRoadStorage(x, y, level)
function Tile.getRoadCarCount(x, y, level)
function Tile.isRoadDeco(x, y, level)
function Tile.getRoadDecoDraft(x, y, level)
function Tile.setRoadDecoDraft(draft, x, y, level)
Show
Util
function Util.collectRectTiles(x, y, w, h, noCorners)
function Util.unite(...)
Show
Vector
function Vector:new(x, y, z)
Example:

function Vector:length()
Example:
print(a:length())

number function Vector:dot(o) is defined as > a1 * b1 + a2 * b2 + a3 * b3
Example:
a:dot(b)

vector function Vector:cross(o) Returns the cross product of two vectors a and b.
Example:
a:cross(b)

function Vector:normalized()
Example:
assert(b:length() == 1)

function Vector:copy()
Example:
local assert(a == b)

string function Vector:__tostring() Returns a readable representation of the vector. Usually used for debug purposes.
Example:
print(tostring(Vector(1, 2, 3)))

function Vector:__add(o)
function Vector:__mul(o)
function Vector:__div(o)
function Vector:__sub(o)
function Vector:__unm()
function Vector:__eq(o)
Last edited by FranchuFranchu on Sat Jun 22, 2019 17:25, edited 1 time in total.
Reason: Update to 741
</failedxss>

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 787
Joined: Sun May 28, 2017 0:07
Location: In the blogosphere
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua API documentation [550]

#4

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

[Empty space to use when the documentation gets too big to fit in 2 posts]
</failedxss>

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

Platform

Plugin Creator

Re: Lua API documentation [550]

#5

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?

User avatar
FranchuFranchu
Inhabitant of a Country
Reactions:
Posts: 787
Joined: Sun May 28, 2017 0:07
Location: In the blogosphere
Plugins: Show
Version: Beta

Platform

Plugin Creator

Re: Lua API documentation [550]

#6

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
</failedxss>

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

Platform

Re: Lua API documentation [550]

#7

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: Wekabu city and 1 guest