Skip to content
Loom0.1.0
Source

Get started

Coming from Blueprints

If you have built with Blueprint graphs, you already know what Loom does. Each node you would place has a line of Loom that does the same thing.

Execution runs from the top of a function to the bottom, one statement per line, so there are no white execution wires to draw. Values that flow along data wires become arguments and variables.

  • Event
  • Function call
  • Flow control
  • Variable
  • Pure
Variable
var Count: int = 0

In the My Blueprint panel. editable makes it Instance Editable, and private ticks Private.

Function
fn Square(x: int) -> int {
return x * x
}
Function input default
fn Hit(amount: int, times: int = 1) -> int {
return amount * times
}

A call that leaves it out gets the default, like an input’s default value in the Details panel: Hit(5) is Hit(5, 1).

Function with several outputs
fn Lookup(key: string, out found: bool, out value: int) {
found = key == "a"
value = 1
}

A call gives the outputs back by name: let r = Lookup("a"), then r.found.

Pure function
private pure fn Area() -> int {
return Width * Height
}

pure makes a node with no exec pins, as the Pure checkbox does. private and protected set its Access Specifier.

Macro, or collapsed graph
fn AddPoints(points: int) {
Count = Count + points
}

Write it as a function, and call it wherever the macro or collapsed graph was.

Blueprint Function Library
BPL_Math.lm
blueprint BPL_Math : BlueprintFunctionLibrary at /Game/BPL_Math
pure fn Double(x: int) -> int {
return x * 2
}

Any Blueprint calls it as BPL_Math.Double(4). See Function libraries.

Event Dispatcher
dispatcher Scored(points: int)
Add Component
component Sound: AudioComponent

Only in an actor’s Blueprint.

Blueprint Interface
BPI_Interactable.lm
interface BPI_Interactable at /Game/BPI_Interactable {
fn Interact(by: Actor)
fn CanInteract(by: Actor) -> bool
}

An interface is its own asset too, so it gets its own source file, with one function per line and no bodies. A Blueprint that implements it handles each function with on.

Implement Interface
implements BPI_Interactable
on Interact(by: Actor) {
Open = !Open
}

One implements line per interface, after the header. Its functions are ordinary on handlers.

Interface Message
if implements(thing, BPI_Interactable) {
cast(thing, BPI_Interactable).Interact(by)
}

implements(…) is Does Implement Interface. A call through cast(…) is the message: on an object without the interface, it does nothing.

Structure
S_Cell.lm
struct S_Cell at /Game/Types/S_Cell {
X: int
Y: int = 1
Visited: bool
}

A struct is its own asset, so it gets its own source file. Fields are listed one per line, each starting at zero or at its default. Code makes one as S_Cell(X: 2) and reads cell.Y.

Enumeration
E_Tool.lm
enum E_Tool at /Game/Types/E_Tool {
Hammer
Saw "Hand Saw"
Chisel
}

An enum is its own asset, so it gets its own source file. Values are listed one per line. A label in quotes is what the editor shows, and code uses the name: E_Tool.Saw.

Event BeginPlay
on ReceiveBeginPlay {
Sum(100)
}

Events use their function name in the engine, here ReceiveBeginPlay.

Custom Event
event Pulse(times: int) {
for i in 1..times {
Lit = !Lit
KismetSystemLibrary.Delay(0.5)
}
}

Called like a function: Pulse(3).

Call Scored
Scored.broadcast(100)
Bind Event to On Audio Finished
Sound.OnAudioFinished.bind(Finished)
Unbind Event / Unbind all Events
Sound.OnAudioFinished.unbind(Finished)
Scored.unbind_all()
Create Event
KismetSystemLibrary.K2_SetTimerDelegate(other.K2_DestroyActor, 5.0, false)

Name the function where an event is expected: one of this Blueprint’s, such as Blink, or another object’s.

Replicated variable
Run on Server, or Multicast

Loom is single-player for now: variables don’t replicate, and events can’t run on the server or on clients.

Branch
if x < 0 {
return -1
} else {
return 1
}

The condition must be a bool.

While Loop
while i <= n {
i = i + 1
}
For Loop
for i in 1..10 {
total = total + i
}

Counts from the first number to the last, both included, as ForLoop does.

For Each Loop
for name in Names {
}

for key, value in map walks a map.

For Each Loop with Break
for v in values {
if v < 0 {
break
}
}

break leaves the loop, like the Break pin. continue skips to the next pass, which no Blueprint node does. Both work in any loop.

Switch on Int
match count {
0 {
Hide()
}
1, 2 {
ShowFew()
}
else {
ShowMany()
}
}

The first arm that lists the value runs. Strings, names and enums work the same way. See match.

Select
let speed = if running { 600.0 } else { 300.0 }

Only the side chosen is computed. See If expressions.

Return Node
return total
Set Count
Count = 1
Increment Int
Count += 1

Also -=, *=, /=, %=, &= and |=, on variables, fields, and array and map items.

Local variable
let count = 3
Add (int + int)
Lives + 1

Calls KismetMathLibrary.Add_IntInt, as the node does.

Cast To Actor
cast(thing, Actor)

Gives none when it isn’t one, instead of a Cast Failed pin.

Make Array
["a", "b"]
Create Widget
create_widget(WBP_Panel)
Print String
KismetSystemLibrary.PrintString("hi")

Any library function is called by its class and name.

Delay
var Ready: bool = false
on ReceiveBeginPlay {
KismetSystemLibrary.Delay(2.0)
Ready = true
}

The handler pauses at the call and goes on once the wait is over. Only an event’s handler can wait. See Waiting.

Set Timer by Function Name
var Lit: bool = false
on ReceiveBeginPlay {
KismetSystemLibrary.K2_SetTimer(self, "Blink", 0.5, true)
}
fn Blink() {
Lit = !Lit
}
Set Timer by Event
var Lit: bool = false
on ReceiveBeginPlay {
KismetSystemLibrary.K2_SetTimerDelegate(Blink, 0.5, true)
}
fn Blink() {
Lit = !Lit
}
Timeline

Loom has no timelines. Change the value a little on each Tick, or with a timer.

  • A pure node on its own does nothing, so a pure call on its own line is refused.
  • A parameter cannot be assigned. Copy it into a let first.
  • The graph Loom makes is not meant for editing: change the .lm file, and the next build remakes the graph.

Next steps