Value types
vec3
A 3D vector: a position, a size, a direction, a speed. Units are KHIM units (a character is about 5 tall).
local v = vec3(1, 2, 3)
print(v.x, v.y, v.z)
print(v.magnitude) -- its length
print(v.unit) -- the same direction, length 1
local sum = v + vec3(0, 1, 0)
local twice = v * 2
local dot = v:dot(vec3(1, 0, 0))
local cross = v:cross(vec3(0, 1, 0))
local halfway = v:lerp(vec3(10, 0, 0), 0.5)
local distance = (a.position - b.position).magnitudevec3(x, y, z) | Missing numbers are 0 |
vec3.zero, vec3.one, vec3.up | (0,0,0), (1,1,1), (0,1,0) |
x, y, z, magnitude, unit | Read-only |
dot(other), cross(other), lerp(goal, alpha) | |
+, -, *, /, unary - | With another vec3, or a number for * and / |
vec2
The same in 2D, for UI anchors, screen points and texture tiling: vec2(x, y), vec2.zero, vec2.one, x, y, magnitude, unit, + - * /.
Colours
local red = rgb(255, 0, 0) -- 0 to 255
local orange = rgb("#ffaa00") -- hex
local blue = hsv(0.6, 0.8, 1) -- hue, saturation, value, 0 to 1
print(red.r, red.g, red.b) -- 0 to 1
local pink = red:lerp(rgb(255, 255, 255), 0.5)transform
A position and a turn - where something is and which way it faces.
local t = transform(0, 10, 0) -- at (0, 10, 0), not turned
local u = transform(vec3(0, 10, 0))
local look = transform.lookAt(vec3(0, 5, 10), vec3(0, 0, 0)) -- at the first point, facing the second
local turned = transform.angles(0, math.rad(90), 0) -- a quarter turn about Y (radians)
local both = t * turned -- moved, then turned
print(look.position, look.forward, look.right, look.up)transform.identity | At the origin, not turned |
position, forward, right, up | vec3s |
inverse() | The opposite move |
lerp(goal, alpha) | Between two, smoothly |
toWorld(other), toLocal(other) | Another transform from this one's space to the world's, and back |
pointToWorld(point), pointToLocal(point) | The same for a point |
t * other | One after the other; t * vec3 is a point moved by t |
t + vec3, t - vec3 | Moved, not turned |
A part's transform is its position and turn: part.transform = transform.lookAt(part.position, target.position) points it at the target.
dim
A UI position or size: a scale (a share of the parent) and an offset (UI points), for X and Y.
dim(0.5, 0, 0, 40) -- half the parent's width, 40 points high
dim.scale(1, 0.5) -- the parent's whole width, half its height
dim.px(200, 50) -- 200 x 50 points
local d = dim(0.5, 10, 0, 0)
print(d.x.scale, d.x.offset, d.y.scale, d.y.offset)Events and connections
An event is something that happens; connect a function to it:
event:connect(fn) | fn every time; returns a connection |
event:once(fn) | fn the first time only |
event:wait() | Waits for the next time and returns what it fired with |
connection:disconnect() | Stop |
connection.connected | Whether it still is |
Tween options
object:tween(goals, time) or object:tween(goals, options):
| Option | |
|---|---|
time | Seconds |
style | "Linear", "Sine", "Quad", "Cubic", "Quart", "Back", "Bounce", "Elastic" |
direction | "In", "Out", "InOut" |
repeats | How many more times; -1 forever |
reverses | Goes back again each time |
delay | Seconds before it starts |
It returns a tween with completed (an event) and cancel().
Raycast result
world:raycast(origin, direction) returns nil or a table: part, position, normal, distance.
Strings for choices
| Property | Values |
|---|---|
part.shape | "Block", "Ball", "Cylinder", "Wedge" |
part.material | "Plastic", "Smooth", "Neon", "Glass", "Metal", "Wood", "Grass", "Brick", "Concrete", "Sand", "Rock", "Water", "Leaves", "Marble", "Granite", "Slate", "Cobblestone", "Pebble", "WoodPlanks", "DiamondPlate", "CorrodedMetal", "Foil", "Fabric", "Ice", "Snow", "Sandstone", "Mud", "Ground", "Asphalt", "CrackedLava", "CeramicTiles", "Pavement", "RoofShingles", "ForceField" |
| A face | "Front" (-Z), "Back", "Left", "Right", "Top", "Bottom" |
label.textAlign | "Left", "Center", "Right" |
label.font | "Default", "Bold", "Display" |
camera.mode | "Follow", "Fixed", "FirstPerson" |
body.state | "Idle", "Walking", "Jumping", "Falling", "Climbing", "Sitting", "Dead" |
| Keys | "A"-"Z", "Zero"-"Nine", "Space", "Return", "Tab", "Backspace", "Escape", "LeftShift", "RightShift", "LeftControl", "RightControl", "LeftAlt", "RightAlt", "Up", "Down", "Left", "Right" |
What net and data carry
net | data | |
|---|---|---|
nil, booleans, numbers, strings | Yes | Yes |
vec3, vec2, colours, transforms | Yes | Yes |
| Parts and players | Yes | No |
| Tables of the above | Yes | Yes |
| Size | 16 KB | 16 KB |