Welcome to CC-Scripts’s documentation!
Overview
Danger
Work in Progress
Bank
Danger
Work in progress
wget https://raw.githubusercontent.com/BitTim/CC-Scripts/master/src/apps/Bank/install.lua
install
DNS
Utility
Essentia
Note
This app is created for use with Thaumcraft 6
Overview
Essentia is a set of scripts to control the flow of essentia from an essentia storage room, similar to this one, through one pipe to a consuming machine, like the Thaumatorium.
The app is broken down into 3 scripts, which run on different computers:
Warning
Essentia can only be moved in multiples of 5, due to a limitation in the redstone contraption for consistency reasons
Dependencies
Mods
Structures
ToDo: Insert images here
Important
You also need to have your DNS infrastructure set up and running.
Setup
Prequisites
Each jar in your storage room has to be labeled.
Each jar in your storage room needs to be part of a flow control structure.
For every 15 jars, you need a controller
For each controller, you need a computer with a wireless modem.
For the server, you need a computer with an ender modem.
For the display, you will need a computer with a wireless modem and a 5 x 2 monitor.
Important
It is required to use an ender modem for the server to bypass the distance limit for transmissions
Note
It is recommended to attach a disk drive and a monitor of any size to the server
Automated
Danger
The automated installer is not yet implemented. This section is prewritten for the future.
You need to run the automated installer on every computer placed in the previous step and select the correct install type. To run and execute the autmated installer, run these commands. The installer will accommodate configuring the computer accordingly:
wget https://raw.githubusercontent.com/BitTim/CC-Scripts/master/src/apps/Essentia/install.lua
install
Manual
ToDo: Insert installation instructions
Note
The automated install is recommended.
Definitions
Controller
The program, that manages controlling the essentia valves and reading amount of aspects stored in jars
Contents:
Dependencies
Configurable Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
servedAspects
A list containing the names of all aspects this controller serves. The order of aspects determines the local ID for each aspect.
local servedAspects = {}
Type:
table
Default:
{}
Warning
Please make sure, that the order of the aspects matches the order of the color channels used in the bundled cable. To see the order of the colors, consult the table at the bottom of this page.
outputSide
The side the bundled cable is connected to the computer.
local outputSide = "back"
Type:
string
Default:
"back"
modemSide
The side the wireless modem is connected to the computer.
local modemSide = "top"
Type:
string
Default:
"top"
Requests
FLOW
Release 5 essentia from the specified aspect. Fails if aspect is not serverd by controller or amount of essentia of specified aspect is less than 5.
{head = "FLOW", contents = {aspect = ""}}
request Contents:
Name |
Type |
Default |
Description |
---|---|---|---|
aspect |
|
|
Aspect of which 5 essentia should be released. |
Response contents: nil
PROBE
Probe the amount of specified aspect in jar. Fails if aspect is not serverd by controller.
{head = "PROBE", contents = {aspect = ""}}
Request Contents:
Name |
Type |
Default |
Description |
---|---|---|---|
aspect |
|
|
Aspect of which the amount should be probed. |
Response contents:
Name |
Type |
Description |
---|---|---|
aspect |
|
Aspect in probed jar. |
amount |
|
Amount of stored essentia in probed jar. |
Warning
If aspect
in response contents doesn’t match with aspect
in request contents, then the order of nbtPeripheralTags is most likely faulty.
Constants
Name |
Type |
Value |
---|---|---|
|
|
|
|
|
title
The title of this program.
local title = "Essentia Controller"
Type:
string
Default:
"Essentia Controller"
version
The version of this program.
local version = "v1.0"
Type:
string
Default:
"v1.0"
Internal Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
nbtPeripherals
A list containing the wrapped nbt observer peripherals.
local nbtPeripherals = {}
Type:
table
Default:
{}
sModem
An instance of a secure modem object
local sModem = nil
Type:
sModem
Default:
nil
Local Functions
Note
Local functions are defined in a local scope and thus can only be used within this program. They mainly server as helper functions for the program itself.
getLocalID(aspect)
Converts aspect name to local ID using servedAspects.
local funtion getLocalID(aspect)
...
return localID
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
aspect |
|
|
Aspect to convert to local ID. |
Returns:
Type |
Description |
---|---|
|
Local ID of aspect or 0 if aspect is not served. |
Example:
local servedAspects = {"terra", "aqua", "aer", "ignis", "ordo"}
local localID = getLocalID("aer")
In this case, localID
would equal to 3
, since aer
is the third element in the table
Note
The table servedAspects
would normally be set as a configurable property
sendPulse(id)
Sends a redstone pulse on the specified channel through the bundled wire at outputSide.
local funtion snedPulse(id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
id |
|
|
Local ID of aspect / Channel to send a pulse to. |
Returns: nil
Example:
sendPulse(4)
This would send a redstone pulse on the outputSide on the color channel corresponding to the number 2 ^ (id - 1)
,
in this case 8
, which corresponds to the color lightBlue
as seen here. Thus this command would send a pulse on the lightBlue channel.
Server
The program, that manages requests to controllers and broadcasts them to every specified controller
Contents:
Dependencies
Configurable Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
controllerDomains
A list containing all the domain names of the controllers, which are used to look up the addresses of the controllers.
local controllerDomains = {}
Type:
table
Default:
{}
Important
The specified domain names have to be registered in the DNS Server.
modemSide
The side the wireless modem is connected to the computer.
local modemSide = "top"
Type:
string
Default:
"top"
Requests
FLOW
Release 5 essentia from the specified aspect. Fails if aspect is not serverd by controller or amount of essentia of specified aspect is less than 5.
Note
The server only broadcasts this request to the controllers specified with controllerDomains. The controllers actually handle the requests.
{head = "FLOW", contents = {aspect = ""}}
request Contents:
Name |
Type |
Default |
Description |
---|---|---|---|
aspect |
|
|
Aspect of which 5 essentia should be released. |
Response contents: nil
PROBE
Probe the amount of specified aspect in jar. Fails if aspect is not serverd by controller.
Note
The server only broadcasts this request to the controllers specified with controllerDomains. The controllers actually handle the requests.
{head = "PROBE", contents = {aspect = ""}}
Request Contents:
Name |
Type |
Default |
Description |
---|---|---|---|
aspect |
|
|
Aspect of which the amount should be probed. |
Response contents:
Name |
Type |
Description |
---|---|---|
aspect |
|
Aspect in probed jar. |
amount |
|
Amount of stored essentia in probed jar. |
Warning
If aspect
in response contents doesn’t match with aspect
in request contents, then the order of nbtPeripheralTags is most likely faulty.
Constants
Name |
Type |
Value |
---|---|---|
|
|
|
|
|
title
The title of this program.
local title = "Essentia Server"
Type:
string
Default:
"Essentia Server"
version
The version of this program.
local version = "v1.0"
Type:
string
Default:
"v1.0"
Internal Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
controllerAddresses
A list containing the resolved addresses of the controllers specified in controllerDomains.
local controllerAddresses = {}
Type:
table
Default:
{}
sModem
An instance of a secure modem object
local nbtPeripherals = {}
Type:
sModem
Default:
nil
Display
Danger
Work in progress
Contents:
Keycard
Danger
Work in progress
Letter Studio
Danger
Work in progress
Server Client Framework
Danger
Work in progress
Turtle
Danger
Work in progress
ComLib
A library for communicating between two computers in a server and client relation
Contents:
Dependencies
Functions
open()
Opens secure connection on modem on specified side
function comlib.open(side)
...
return sModem
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
side |
|
|
Side of the modem for the secure connection. |
Returns:
Type |
Description |
---|---|
|
Instance of secure modem object. |
Example:
local comlib = require("comlib")
local sModem = comlib.open("front")
This would open a secure connection on the modem at the front of the computer, accessible with the sModem
variable.
getAddress()
Returns address of current computer
function comlib.getAddress()
...
return address
end
Arguments: nil
Returns:
Type |
Description |
---|---|
|
Address of current computer. |
Example:
local comlib = require("comlib")
print(comlib.getAddress())
This would print the address of the current computer, e.g. b38a:a780:bd82:cd56:195f
sendRequest()
Creates a request packet with the status REQUEST
, sends it to the specified address
and will wait for and return a response packet.
This function will return -1
if the receiving operation times out.
function sendRequest(address, header, contents, timeout)
...
return response
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
address |
|
|
Address of the receiver. |
header |
|
|
Header of the request packet. |
contents |
|
|
Additional contents of the request packet. |
timeout |
|
|
Number of seconds before the timeout would get triggered. |
Note
Additional contents depend on the type of request and what the receiver is expecting
Returns:
Type |
Description |
---|---|
|
Received response packet. |
Warning
This function returns -1
instead of the above, if one of these conditions is met:
Not being able to connect to the address.
Sender of the response packet is
nil
.Deserialized response packet is
nil
.If response header does not match request header.
Example:
local comlib = require("comlib")
comlib.sendRequest("873b:a87c:fe93:846:c9d3", "GET", {key = "Hello"}, 3)
In this example, a request packet with the header "GET"
and the contents {key = "Hello"}
will be sent to "873b:a87c:fe93:846:c9d3"
.
For this example, we will assume that the receiver expects key
in contents, which is why key = "Hello"
is specified here.
If no response is received within 3
seconds, the function would timeout and return -1
.
Created packet: {head = "GET", status = "REQUEST", contents = {key = "Hello"}}
sendResponse()
Sends a response to the specified receiver with specified head, status and additional contents
function comlib.sendResponse(address, header, status, contents)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
address |
|
|
Address of the receiver. |
header |
|
|
Header of the response packet. |
status |
|
|
Status of the response packet (e.g. “OK” or “FAIL”). |
contents |
|
|
Additional contents to add to the packet. |
Note
Additional contents depend on the type of response and what the receiver is expecting
Returns: nil
Example:
local comlib = require("comlib")
comlib.sendResponse("b38a:a780:bd82:cd56:195f", "GET", "OK", {value = "Test"})
In this example, a response packet with the header "GET"
and the status "OK"
will be sent to "b38a:a780:bd82:cd56:195f"
.
For this example, we will assume that the receiver expects value
in contents, which is why value = "Test"
is specified here.
Created packet: {head = "GET", status = "OK", contents = {value = "Test"}}
broadcast()
Broadcasts a request to multiple receivers and collects all responses. If a response of a receiver fails (sendRequest returns -1
), its response will fall back to this one: {head = header, status = "FAIL", contents = {}}
.
Note
This function calls sendRequest() for each receiver.
function comlib.broadcast(addresses, header, contents, timeout)
...
return responses
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
addresses |
|
|
Addresses of the receivers. |
header |
|
|
Header of the response packet. |
contents |
|
|
Additional contents to add to the packet. |
timeout |
|
|
Number of seconds before the timeout would get triggered. |
Note
Additional contents depend on the type of response and what the receiver is expecting
Returns:
Type |
Description |
---|---|
|
Received response packets. |
Example:
local comlib = require("comlib")
local responses = {}
local receivers = {
"01ae:4a1e:0195:6e6e:56af",
"e990:4b07:961f:0b4b:c50a:",
"7a57:2c08:9d08:7bac:91ff"
}
responses = comlib.broadcast(receivers, "TEST", {})
This would send the packet {head = "TEST", status = "REQUEST", contents = {}}
to all three specified receivers and would store there responses in responses
.
DNSLib
A library for various DNS operations
Important
To use this library, a functioning DNS Server is required.
Contents:
Dependencies
Properties
Name |
Type |
Default |
---|---|---|
|
|
dnsAddress
The address of the DNS Server.
dnslib.dnsAddress = ""
Type:
string
Default:
""
Note
This property is set using init()
Functions
init()
Initializes DNSLib and sets dnsAddress to an address read from the /.dnsAddress
file. If the file does not exist the function will return -1
.
function dnslib.init()
...
return success
end
Arguments: nil
Returns:
Type |
Description |
---|---|
|
Initialization success. |
Warning
This function returns -1
instead of the above, if one of these conditions is met:
/.dnsAddress
file does not exist.Address read from
/.dnsAddress
is empty ornil
.
Example:
local dnslib = require("dnslib")
dnslib.init()
This would initialize DNSLib and set dnsAddress to an addres found in /.dnsAddress
.
lookup()
Looks up the specified domain and returns the address of the registered server.
function dnslib.lookup(domain)
...
return address
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
domain |
|
|
Domain to look up. |
Returns:
Type |
Description |
---|---|
|
Address of the corresponding registered server. |
Warning
This function returns -1
instead of the above, if one of these conditions is met:
sendRequest() has errored (Has returned
-1
as well).
Example:
local dnslib = require("dnslib")
local address = dnslib.lookup("test.com")
Here address
would contain the address the DNS Server knows for "test.com"
lookupMultiple()
Looks up the multiple domains and returns the addresses of the registered servers.
Note
This function calls lookup() for each domain.
function dnslib.lookupMultiple(domains)
...
return addresses
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
domains |
|
|
Domains to look up. |
Returns:
Type |
Description |
---|---|
|
Addresses of the corresponding registered servers. |
Warning
This function returns -1
instead of the above, if one of these conditions is met:
Any lookup operation failed (lookup() returned
-1
).
Example:
local dnslib = require("dnslib")
local domains = {
"test1.com",
"test2.com"
}
local addresses = dnslib.lookupMultiple(domains)
Here addresses
would contain the addresses of both, test1.com
and test2.com
. If either one of those would cause an error in lookup(), addresses
would contain -1
.
LogLib
A library for logging to the screen, which is either the built-in computer screen or a connected monitor of any size.
Contents:
Functions
init()
Initializes LogLib with setting the title in the computer and, if a monitor is present, setting the title in the monitor and redirecting output to the monitor.
function loglib.init(title, version)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
title |
|
|
Title that will be displayed at the top of the screen. |
version |
|
|
Version that will be displayed at the top of the screen. |
Returns: nil
Example:
local loglib = require("loglib")
loglib.init("Test PC", "V1.0")
This would initialize LogLib and would display the text Test PC V1.0
at the top of the screen.
Warning
If a monitor is present, all text ouput will be redirected onto the monitor.
Note
Screen refers to the active output. If no monitor is present, the active output is the computer screen. If a monitor is present, the active output is the monitor.
log()
Loggs a message with a tag and the current in-game time to the screen
function loglib.log(tag, msg)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
tag |
|
|
Tag that will be displayed. |
msg |
|
|
Message that will be displayed. |
Example:
local loglib = require("loglib")
loglib.log("Test", "This is a test message")
This would display the text <5.345> [Test] This is a test message
, if we assume the current in-game time is 5.345
.
Returns: nil
Important
LogLib has to be initialized when using this function.
Local Functions
Note
Local functions are defined in a local scope and thus can only be used within this program. They mainly server as helper functions for the program itself.
setTitle(title, version)
Sets the title displayed at the top of the screen.
function loglib.setTitle(title, version)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
title |
|
|
Title that will be displayed at the top of the screen. |
version |
|
|
Version that will be displayed at the top of the screen. |
Returns: nil
Example:
local loglib = require("loglib")
loglib.setTitle("Test PC", "V1.0")
This would display the text Test PC V1.0
at the top of the screen.
UILib
A library for various UI actions and elements, like drawing and chacking for events.
Contents:
Classes
Style
This is a class, that contains and handles styles for UI elements for different states.
Contents:
States
The possible states for UI element styles. The flag pressed refers to the flag of the UI element, that is raised when it gets clicked. The flag disabled refers to the flag of the UI element, that can be raised to disable said element.
State |
pressed |
disabled |
---|---|---|
Normal / Default |
|
|
Pressed |
|
|
disabled |
|
|
Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
normalFG
Foreground color in default state.
uilib.Style.normalFG = colors.white
Type:
number
Default:
colors.white
Note
It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.
normalBG
Background color in default state.
uilib.Style.normalBG = colors.gray
Type:
number
Default:
colors.gray
Note
It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.
pressedFG
Foreground color in pressed state.
uilib.Style.pressedFG = colors.white
Type:
number
Default:
colors.white
Note
It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.
pressedBG
Background color in pressed state.
uilib.Style.pressedBG = colors.lime
Type:
number
Default:
colors.lime
Note
It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.
disabledFG
Foreground color in disabled state.
uilib.Style.disabledFG = colors.gray
Type:
number
Default:
colors.gray
Note
It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.
disabledBG
Background color in disabled state.
uilib.Style.disabledBG = colors.lightGray
Type:
number
Default:
colors.lightGray
Note
It is recommended to set this property with the Colors(API). If you choose to set this property with numeric values directly, please consult the table at the bottom of this page for the correct values.
Functions
new()
Creates a new instance of Style and returns it.
function uilib.Style:new(normalFG, normalBG, pressedFG, pressedBG, disabledFG, disabledBG)
...
return style
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
normalFG |
|
|
Foreground color for default state. |
normalBG |
|
|
Background color for default state. |
pressedFG |
|
|
Foreground color for pressed state. |
pressedBG |
|
|
Background color for pressed state. |
disabledFG |
|
|
Foreground color for disabled state. |
disabledBG |
|
|
Background color for disabled state. |
Returns:
Type |
Description |
---|---|
Instance of Style with specified properties. |
Example:
local uilib = require("uilib")
local style = uilib.Style:new(colors.red. colors.lightGray)
This would create an instance of Style with colors.red
as normalFG and colors.lightGray
as normalBG.
All other properties would be set to their respective default value.
getColors()
Returns the foreground and background color for the current state of the UI element.
function uilib.Style:getColors(pressed, disabled)
...
return fg, bg
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
pressed |
|
|
Flag if UI element has been clicked. |
disabled |
|
|
Flag if UI element has been disabled. |
Returns:
Type |
Description |
---|---|
|
Foreground color for current state of UI element. |
|
Background color for current state of UI element. |
Example:
local uilib = require("uilib")
local style = uilib.Style:new(colors.red. colors.lightGray)
local fg, bg = style:getColors(false, false)
This would create an instance of Style with colors.red
as normalFG and colors.lightGray
as normalBG.
After that it would get the foregournd and background color for the default state, since pressed
and disabled
are both false
.
So fg
and bg
would contain colors.red
and colors.lightGray
respectively.
Group
A UI element, that holds multiple other UI elements and draws them together.
Contents:
Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
|
|
|
x
X component of the position on the screen.
uilib.Group.x = nil
Type:
number
Default:
nil
y
Y component of the position on the screen.
uilib.Group.y = nil
Type:
number
Default:
nil
elements
List of all UI elements included within the group.
uilib.Group.elements = {}
Type:
table
Default:
{}
visible
Contains information about the group being visible or not.
uilib.Group.visible = true
Type:
boolean
Default:
true
Functions
new()
Function to create a new instance of Group.
function M.Group:new(x, y, elements)
...
return group
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
x |
|
|
X component of position of the group. |
y |
|
|
Y component of position of the group. |
elements |
|
|
List of all contained UI elements. |
Important
The elements
list must contain the elements with a string key attached to them, e.g. {label = elementVar}
.
Important
When you add a UI element to a group, the x
and y
parameters will become local to the group, which means that the actual position of the UI element would be:
(group.x + element.x - 1, group.y + element.y - 1)
.
Returns:
Type |
Description |
---|---|
Instance of Group with specified properties. |
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
This would create an instance of a Group and a Label within the created group.
The Label would be drawn at position (5, 6)
.
draw()
Function to draw the group.
function M.Group:draw()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:draw()
This would create an instance of a Group and a Label within the created group and draw it to the screen.
add()
Function to add a UI element to the group.
function M.Group:add(element, id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
element |
|
|
UI element to add. |
id |
|
|
ID to refer to the UI element. |
Important
When you add a UI element to a group, the x
and y
parameters will become local to the group, which means that the actual position of the UI element would be:
(group.x + element.x - 1, group.y + element.y - 1)
.
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {})
group:add(label, "label")
This would create an instance of a Group and a Label, which is being added to the group with the ID "label2
.
remove()
Function to remove a UI element from the group.
function M.Group:remove(id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
id |
|
|
ID of the element. |
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:remove("label")
This would create an instance of a Group and a Label within the created group. It would then remove the created label from the group.
get()
Function to get a specific UI element from the group.
function M.Group:get(id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
id |
|
|
ID of the UI element. |
Returns:
Type |
Description |
---|---|
|
UI element with the specified id in the group. |
Warning
This function returns -1
instead of the above, if one of these conditions is met:
No UI element with the specified ID exists.
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
local labelAgain = group:get("label")
This would create an instance of a Group and a Label within the created group.
After that it would store the label element with the ID "label"
in labelAgain
.
show()
Function to make the group visible.
function uilib.Group:show()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:show()
This would create an instance of a Group and a Label within the created group and make it visible.
hide()
Function to make the group invisible.
function uilib.Group:hide()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:hide()
This would create an instance of a Group and a Label within the created group and make it invisible.
Page Handler
A UI element, that holds multiple other UI elements and draws them together.
Contents:
Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
|
|
|
x
X component of the position on the screen.
uilib.Group.x = nil
Type:
number
Default:
nil
y
Y component of the position on the screen.
uilib.Group.y = nil
Type:
number
Default:
nil
elements
List of all UI elements included within the group.
uilib.Group.elements = {}
Type:
table
Default:
{}
visible
Contains information about the group being visible or not.
uilib.Group.visible = true
Type:
boolean
Default:
true
Functions
new()
Function to create a new instance of Group.
function M.Group:new(x, y, elements)
...
return group
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
x |
|
|
X component of position of the group. |
y |
|
|
Y component of position of the group. |
elements |
|
|
List of all contained UI elements. |
Important
The elements
list must contain the elements with a string key attached to them, e.g. {label = elementVar}
.
Important
When you add a UI element to a group, the x
and y
parameters will become local to the group, which means that the actual position of the UI element would be:
(group.x + element.x - 1, group.y + element.y - 1)
.
Returns:
Type |
Description |
---|---|
Instance of Group with specified properties. |
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
This would create an instance of a Group and a Label within the created group.
The Label would be drawn at position (5, 6)
.
draw()
Function to draw the group.
function M.Group:draw()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:draw()
This would create an instance of a Group and a Label within the created group and draw it to the screen.
add()
Function to add a UI element to the group.
function M.Group:add(element, id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
element |
|
|
UI element to add. |
id |
|
|
ID to refer to the UI element. |
Important
When you add a UI element to a group, the x
and y
parameters will become local to the group, which means that the actual position of the UI element would be:
(group.x + element.x - 1, group.y + element.y - 1)
.
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {})
group:add(label, "label")
This would create an instance of a Group and a Label, which is being added to the group with the ID "label2
.
remove()
Function to remove a UI element from the group.
function M.Group:remove(id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
id |
|
|
ID of the element. |
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:remove("label")
This would create an instance of a Group and a Label within the created group. It would then remove the created label from the group.
get()
Function to get a specific UI element from the group.
function M.Group:get(id)
...
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
id |
|
|
ID of the UI element. |
Returns:
Type |
Description |
---|---|
|
UI element with the specified id in the group. |
Warning
This function returns -1
instead of the above, if one of these conditions is met:
No UI element with the specified ID exists.
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
local labelAgain = group:get("label")
This would create an instance of a Group and a Label within the created group.
After that it would store the label element with the ID "label"
in labelAgain
.
show()
Function to make the group visible.
function uilib.Group:show()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:show()
This would create an instance of a Group and a Label within the created group and make it visible.
hide()
Function to make the group invisible.
function uilib.Group:hide()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.black))
local group = uilib.Group:new(2, 2, {label = label})
group:hide()
This would create an instance of a Group and a Label within the created group and make it invisible.
Label
A UI element, that displays plain text.

Labels with two styles.
Contents:
Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
text
Text, which the label will display.
uilib.Label.text = nil
Type:
string
Default:
nil
x
X component of the position on the screen.
uilib.Label.x = nil
Type:
number
Default:
nil
y
Y component of the position on the screen.
uilib.Label.y = nil
Type:
number
Default:
nil
style
Style of the label.
uilib.Label.style = uilib.Style:new()
Type: uilib.Style
Default: Default Style
visible
Contains information about the label being visible or not.
uilib.Label.visible = true
Type:
boolean
Default:
true
Functions
new()
Function to create a new instance of Label.
function M.Label:new(text, x, y, style)
...
return label
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
text |
|
|
Text, which the label will display. |
x |
|
|
X component of position of the label. |
y |
|
|
Y component of position of the label. |
style |
Style of the label. |
Note
Labels can only use the default state for styling.
Returns:
Type |
Description |
---|---|
Instance of Label with specified properties. |
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.gray))
This would create an instance of a Label with the text I am a Label!
with colors.red
text on colors.gray
background at position (4, 5)
.
draw()
Function to draw the label.
function M.Label:draw()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.gray))
label:draw()
This would create an instance of Label and draw it to the screen.
show()
Function to make the label visible.
function uilib.Label:show()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.gray))
label:show()
This would create an instance of Label and make it visible.
hide()
Function to make the label invisible.
function uilib.Label:hide()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local label = uilib.Label("I am a Label!", 4, 5, uilib.Style:new(colors.red, colors.gray))
label:hide()
This would create an instance of Label and make it invisible.
ProgressBar
A UI element that shows a bar, that can be filled to different amounts in multiple orientations.

Different kinds of porgress bar.
Contents:
Properties
Name |
Type |
Default |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minVal
Smallest value the progress bar can display.
uilib.ProgressBar.minVal = nil
Type:
number
Default:
nil
maxVal
Biggest value the progress bar can display.
uilib.ProgressBar.maxVal = nil
Type:
number
Default:
nil
val
Current value the progress bar should display.
uilib.ProgressBar.val = nil
Type:
number
Default:
nil
x
X component of the position on the screen.
uilib.ProgressBar.x = nil
Type:
number
Default:
nil
y
Y component of the position on the screen.
uilib.ProgressBar.y = nil
Type:
number
Default:
nil
w
Width of the progress bar.
uilib.ProgressBar.w = nil
Type:
number
Default:
nil
h
Height of the progress bar.
uilib.ProgressBar.h = nil
Type:
number
Default:
nil
vertical
Enables vertical mode for the progress bar.
uilib.ProgressBar.vertical = false
Type:
boolean
Default:
false
inverted
Enables inverted mode for the progress bar.
uilib.ProgressBar.inverted = false
Type:
boolean
Default:
false
style
Style of the progress bar.
uilib.ProgressBar.style = uilib.Style:new()
Type: uilib.Style
Default: Default Style
visible
Contains information about the progress bar being visible or not.
uilib.ProgressBar.visible = true
Type:
boolean
Default:
true
Functions
new()
Function to create a new instance of ProgressBar.
function M.ProgressBar:new(minVal, maxVal, val, x, y, w, h, vertical, inverted, style)
...
return prog
end
Arguments:
Name |
Type |
Default |
Description |
---|---|---|---|
minVal |
|
|
Smallest value the progress bar can display. |
maxVal |
|
|
Biggest value the progress bar can display. |
val |
|
|
Current value the progress bar should display. |
x |
|
|
X component of position of the progress bar. |
y |
|
|
Y component of position of the progress bar. |
w |
|
|
Width of the progress bar. |
h |
|
|
Height of the progress bar. |
vertical |
|
|
Enables vertical mode for the progres bar. |
inverted |
|
|
Enables inverted mode for the progres bar. |
style |
Style of the progress bar. |
Note
Progress bars can only use the default state for styling.
Returns:
Type |
Description |
---|---|
Instance of ProgressBar with specified properties. |
Example:
local uilib = require("uilib")
local prog = uilib.ProgressBar:new(0, 100, 35, 2, 2, 10, 1, false, false, uilib.Style:new())
This would create an instance of ProgressBar with possible values between 0
and 100
and an initial value of 35
.
The progress bar would be displayed at the position (2, 2)
and would be 10 x 1
pixels in size. It would be in horizontal mode, since vertical
is set to false
.
The style of the progress bar will be the default style.
draw()
Function to draw the progress bar.
function M.ProgressBar:draw()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local prog = uilib.ProgressBar:new(0, 100, 35, 2, 2, 10, 1, false, false, uilib.Style:new())
prog:draw()
This would create an instance of ProgressBar and draw it to the screen.
show()
Function to make the progress bar visible.
function uilib.ProgressBar:show()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local prog = uilib.ProgressBar:new(0, 100, 35, 2, 2, 10, 1, false, false, uilib.Style:new())
prog:show()
This would create an instance of ProgressBar and make it visible.
hide()
Function to make the progress bar invisible.
function uilib.ProgressBar:hide()
...
end
Arguments: nil
Returns: nil
Example:
local uilib = require("uilib")
local prog = uilib.ProgressBar:new(0, 100, 35, 2, 2, 10, 1, false, false, uilib.Style:new())
prog:hide()
This would create an instance of ProgressBar and make it invisible.